I need some help with my LISP.
I am trying to load all of our standard layers to include the layer name, color, linetype and description. The routine works the first time it is run, but if someone re-runs it (i.e. they delete a layer, etc.) the promts change to add in the despription... after the 1st time it asks if you want to replace the current description. I cannot figure out how to make this work both the first time (w/o the extra promt) and the 2nd time (w/ the additional prompt.Any help would be appreciated.
Here is a sample of the code.
(defun c:FPlayers ()
(command "CMDECHO" "1")(terpri) (prompt "Setting layers")(princ)
(command "layer" "unlock" "*" "thaw" "*" "on" "*" "")
(command "layer" "m" "0" "c" "7" "" "l" "Continuous" "" "")
(command "layer" "m" "A-COLS" "c" "yellow" "" "l" "Continuous" "" "")
(command "layer" "d" "Columns" "A-COLS" "")
(command "layer" "m" "A-COLS-GRID" "c" "40" "" "l" "CENTER2" "" "")
(command "layer" "d" "Column Grid" "A-COLS-GRID" "")
(command "layer" "s" "0" "")
(command "CMDECHO" "1")
(prompt "All layers are set")
(princ)
);end defun
IMO, this is exactly the type of situation where the sysvar EXPERT should be honored, but I guess today's current "-layer" programmers didn't know it existed or chose to ignore it for some reason. You can use this function instead.
(defun foo (layer desc) (vla-put-description (vlax-ename->vla-object (tblobjname "Layer" layer) ) desc) ) ;;; use like this (foo "0" "My Desc")
Thank yoy rkmcswain for the quick reply. Unfortunalty, I know just the basics of LISP, so this code is a little over my head. Would you mind explaining/embellishing/etc. a little for me, please?
Do I repeat that for every layer?
Do I put it at the end or betweeen creating each layer?
I'm not at a station with a new-enough version to have the Description option in the Layer command, but when it asks whether you want to replace the Description, is the default option "Yes"? If so, I can suggest another way to do what you're after.
The default is "N" on 2015.
Command: -LAYER Current layer: "0" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: d Enter layer description: test Enter name list of layer(s) to apply description or <select objects>: <*>: 0 Replace existing description(s)? [Yes/No]:? <N> y Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: Command: Command:
By the way, ignoring the replace-the-description problem, you are apparently unaware of the fact that you can do a whole batch of Layer option operations within one Layer command, so you don't need to end it and get back into it all those times:
(command "layer"
"unlock" "*" "thaw" "*" "on" "*"
"m" "0" "c" "7" "" "l" "Continuous" ""
"m" "A-COLS" "c" "yellow" "" "l" "Continuous" ""
"d" "Columns" "A-COLS"
"m" "A-COLS-GRID" "c" "40" "" "l" "CENTER2" ""
"d" "Column Grid" "A-COLS-GRID"
"s" "0
"" ; terminate the one collective Layer command
)
If the default on replacing a Description is Yes, the other approach I will suggest will require breaking that into a few pieces, but most of it can remain in one Layer command.
@rkmcswain wrote:
The default is "N" on 2015.
....Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: ....
In that case, here's a really cheap trick you can try: Since Yes is not an option in the "base" Layer sub-prompt, you can supply that as an answer to the mere possibility that it might ask that question. In the individual-Layer-commands approach:
(command "layer" "d" "Columns" "A-COLS" "_yes" "")
If there's no description for it to ask whether you want to replace, an "Invalid option keyword" message will go by, but it will then just go back to the base prompt and carry on, in the above case to the Enter that closes the Layer command.
But that also has the advantage over the other suggestion I was going to make [if the default was Yes], that it ought to work in an overall-combined-into-one-Layer-command approach:
(command "layer"
"unlock" "*" "thaw" "*" "on" "*"
"m" "0" "c" "7" "" "l" "Continuous" ""
"m" "A-COLS" "c" "yellow" "" "l" "Continuous" ""
"d" "Columns" "A-COLS" "_yes"
"m" "A-COLS-GRID" "c" "40" "" "l" "CENTER2" ""
"d" "Column Grid" "A-COLS-GRID" "_yes"
"s" "0
"" ; terminate the one collective Layer command
)