lisp crashing script

Discussion in 'AutoCAD' started by TJARONIK, Jul 25, 2003.

  1. TJARONIK

    TJARONIK Guest

    Hello,
    I wrote this lisp routine to change the attributes of a user selected block to color bylayer. It seems to work fine in stand alone but crashes when run in a script. I have attatched a text file with the lisp coding, the script coding and the command line result.

    Any ideas on making the lisp code better and any ideas on getting it to work in a script?

    Thanks in advance!

    "Catch" Ya Later,
    Timothy Jaronik
     
    TJARONIK, Jul 25, 2003
    #1
  2. TJARONIK

    RDI Guest

    Running A2K here.



     



    I don't get the same error.  The following is the result of running the script file.  What is the purpose of the (while (< (getvar "cmdactive") 1) (nil)) statement?



     



    When I comment this statement out and run the script, I don't get ANY error message.



     



    As far as cleaning it up goes, I'd turn off cmdecho at the start of your lisp routine.  I'd also use "Undo-Begin" and "Undo-End" to make it one big group.



     



    The routine below uses both these concepts.  I'd also put in some kind of error handler.



     



    HTH



     



    (defun C:ATC ( / )
      (setq echo (getvar "cmdecho"))    ;<----------------
      (setvar "cmdecho" 0)    ;<----------------



      (command "undo" "be")    ;<----------------
      (setq BLKN (getstring "\nName of Block to Edit<*>: ")
    ATTN (getstring "\nName of Attribute to Edit<*>:"))
      (command "attedit" "y" BLKN ATTN "*" "c" (getvar "extmin")(getvar "extmax") "color" "bylayer")
      (while (> (getvar "cmdactive") 0)
    (command "next")
    (command "color" "bylayer"))
    ;(while (< (getvar "cmdactive") 1)    ;<----------------
    ;(nil))    ;<----------------
    (princ)
      (setvar "cmdecho" echo)    ;<----------------



      (command "undo" "end")    ;<----------------
        )



     



     



    ;command result starts here



     



    Command: ATC
    Name of Block to Edit<*>: REV
    Name of Attribute to Edit<*>:*
    attedit
    Edit attributes one at a time? [Yes/No] <Y>: y
    Enter block name specification <*>: REV
    Enter attribute tag specification <*>: *
    Enter attribute value specification <*>: * Select Attributes: c
    Specify first corner: Specify opposite corner: 12 found



     



    12 attributes selected.
    Enter an option [Value/Position/Height/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <4 (cyan)>: bylayer
    Enter an option [Value/Position/Height/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <4 (cyan)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <3 (green)>: bylayer
    Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: next
    Enter an option [Value/Position/Height/Style/Layer/Color/Next] <N>: color
    Enter new color name or value <4 (cyan)>: bylayer
    Enter an option [Value/Position/Height/Style/Layer/Color/Next] <N>: next
    Command: color
    Enter default object color <BYLAYER>: bylayer
    Command: ; error: no function definition: nil




    "TJARONIK" <> wrote in message news:...

    Hello,
    I wrote this lisp routine to change the attributes of a user selected block to color bylayer. It seems to work fine in stand alone but crashes when run in a script. I have attatched a text file with the lisp coding, the script coding and the command line result.

    Any ideas on making the lisp code better and any ideas on getting it to work in a script?

    Thanks in advance!

    "Catch" Ya Later,
    Timothy Jaronik






    LISP STARTS HERE:
    ;
    ; Routine to search for a user selected block within the definded drawing limits and
    ;change the attributes of that block to color bylayer.
    ; By Timothy J. Jaronik
    ; July, 2003
    ;
    ;
    (defun C:ATC ( / )
      (setq BLKN (getstring "\nName of Block to Edit<*>: ")
    ATTN (getstring "\nName of Attribute to Edit<*>:"))
      (command "attedit" "y" BLKN ATTN "*" "c" (getvar "extmin")(getvar "extmax") "color" "bylayer")
      (while (> (getvar "cmdactive") 0)
    (command "next")
    (command "color" "bylayer"))
    (while (< (getvar "cmdactive") 1)
    (nil))
    (princ)
        )
    SCRIPT STARTS HERE:
    ;
    ATC REV *
    ;
    SAVEAS 2000

    COMMAND LINE RESULT STARTS HERE:
    Command:
    Command: scr
    SCRIPT
    Command: ATC
    Name of Block to Edit<*>: REV
    Name of Attribute to Edit<*>:*
    16 found
    Unknown command "NEXT".  Press F1 for help.
    no function definition: nil
     
    RDI, Jul 25, 2003
    #2
  3. TJARONIK

    TJARONIK Guest

    cmdactive is so that the routine will continue to the next attribute. If you notice that at the end of the example you showed me the color command is activated and it sets the current color of the current layer to bylayer. not supposed to be part of the routine. not that it is a bad thing but if a user has the color set it will reset the color to bylayer.

    I guess in a nut shell all I want to be able to do is change a revision block that has the attributes forced to yellow to a color of bylayer without having to burst the block and change the color to bylayer and be able to run it from a script. I believe I have over 700 drawings to do this to. So, you can see my need for some automation. :)

    I will incorporate your ideas into the lisp. Thank you.

    "Catch" Ya Later,
    Timothy Jaronik
     
    TJARONIK, Jul 25, 2003
    #3
  4. TJARONIK

    TJARONIK Guest

    my mistake...the cmdactive 1 part was my attempt at stopping the routine once the attedit command finished looping through all the attributes.
     
    TJARONIK, Jul 25, 2003
    #4
  5. TJARONIK

    rdi Guest

    <<"TJARONIK" <> wrote in message news:...



    cmdactive is so that the routine will continue to the next attribute. If you notice that at the end of the example you showed me the color command is activated and it sets the current color of the current layer to bylayer. not supposed to be part of the routine. not that it is a bad thing but if a user has the color set it will reset the color to bylayer.>>



     



    Not sure if we're talking about the same thing here.  It is NOT possible to set a layer's color setting to "Bylayer".  I think what you meant to say was set the Current color to Bylayer.  As far as being part of the routine, it was in your original code--I just changed the code to try and fix the problem and improve ease of use.  The second while loop does NOTHING and as such, it is not needed.  The first while loop will not end until after the attedit command is finished.



     



    I think my original code should do what you're looking for.



    <<I guess in a nut shell all I want to be able to do is change a revision block that has the attributes forced to yellow to a color of bylayer without having to burst the block and change the color to bylayer and be able to run it from a script. I believe I have over 700 drawings to do this to. So, you can see my need for some automation. :) >>

    Oh yes!  I am definitely a believer in automation when possible.  This is a perfect example of requiring it.

    Recently I had to change the total number of sheets and the date (someone had put these items in each individual sheet rather than in the border xref).  I wrote a routine that went through, searched for the date and total sheet count and changed them.
    --

    RDI

     



    (remove the exclamation from the email address)
     
    rdi, Jul 26, 2003
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.