How do I change a default answer within the Layer Command?
Specifically, I am writing a Lisp to that makes our standard layers. When it makes the layer the 1st time it is run, it works fine. Any subsequent times I get a prompt when giving the layer a description that asks me if I want to replace the existing Description. The default answer is "NO". How to i suppress that promt or change the default to "YES"? I can't answer that question thw way my code is written, because it is not asked the 1st time it is run.
Here is a sample of what I have written for each layer.
(command "layer" "m" "A-COLS" "c" "yellow" "" "l" "Continuous" "" "d" "Columns" "A-COLS" "" "" "")
I am open to suggestions (i.e. if/then) if it not too complicated. I am a novice when it comes to Lisp.
Solved! Go to Solution.
Solved by perkins76. Go to Solution.
Solved by scot-65. Go to Solution.
Solved by phanaem. Go to Solution.
Try this....
(defun C:test () (setvar 'cmdecho 0) (foreach lay '(("A-COL1" "1" "Continuous" "Columns1") ("A-COL2" "2" "Hidden" "Columns2")) (if (not (tblsearch "LAYER" (car lay))) (command "_.-layer" "_make" (car lay) "_color" (cadr lay) "" "_ltype" (caddr lay) "" "_description" (cadddr lay) (car lay) "" ) );if );foreach (princ) )
I don't think smaher12's approach is going to fix it -- see the discussion at the same question over in the 2013-14-15 Forum. [It's not really considered "polite" to post the same question in more than once place, but I think this is a better place for it, since it's not really version-specific except in applying only to all versions since the Description option came along.]
I would suggest you try something I've done in related situations -- give it the answer you want in all cases! I'm not at my location with a newer AutoCAD to verify this, and where I am with an older version the Description option is not available, but try this:
(command "layer" "m" "A-COLS" "c" "yellow" "" "l" "Continuous" "" "d" "Columns" "A-COLS" "_yes" "")
If my guess is correct, it will cover the situation on subsequent running, in which the question is asked, but what will happen if the Layer doesn't yet exist [the first time], or doesn't yet have a Description, is this:
When the _yes comes along, it won't have asked the question about replacing the Description, but it will be at the "base" Layer-command prompt. A message will go by that Yes is an "Invalid option keyword," but it won't give you any real trouble -- it will just go back to the "base" prompt, and the final Enter [one fewer than you had] will end the Layer command.
You should only make a layer once. If the layer already exists, you should assume the settings are correct. If they aren't, there are better ways of managing standards than one-off lisps.
Suggestion
(if (tblsearch "layer" "A-COLS") (setvar "clayer" "A-COLS") (command "layer" "m" "A-COLS" "c" "yellow" "" "l" "Continuous" "" "d" "Columns" "A-COLS" "") )
@perkins76 wrote:
How do I change a default answer within the Layer Command?
Specifically, I am writing a Lisp to that makes our standard layers. When it makes the layer the 1st time it is run, it works fine. Any subsequent times I get a prompt when giving the layer a description that asks me if I want to replace the existing Description. The default answer is "NO". How to i suppress that promt or change the default to "YES"? I can't answer that question thw way my code is written, because it is not asked the 1st time it is run.
Here is a sample of what I have written for each layer.
(command "layer" "m" "A-COLS" "c" "yellow" "" "l" "Continuous" "" "d" "Columns" "A-COLS" "" "" "")
...
Hi perkins76,
you'll need to test the layer existence, and if true, test if any description is stored in AcAecLayerStandard application as xdata,
or start the layer command, and test only the description, to finalize the command.
As a demo:
(defun c:test (/ _test) (defun _test (lname descr / lay) ;; test if "AcAecLayerStandard" exist (if (setq lay (assoc -3 (entget (tblobjname "LAYER" lname) '("AcAecLayerStandard")))) ;; if true test if empty description (if (= (cdr (last (cadr lay))) "") ;; if true (command "d" descr lname "") ;; if have description (command "d" descr lname "_Y" "") ) ;; if "AcAecLayerStandard" don't exist (command "d" descr lname "") ) (princ) ) (command "layer" "m" "A-COLS" "c" "yellow" "" "l" "Continuous" "") (_test "A-COLS" "Columns") (princ) )
Hope that helps
Henrique
You can use this method which makes new layers or changes properties of existing layers.
(defun c:stdlayer ( / acdoc layers layerlist) (vl-load-com) (setq acdoc (vla-get-activedocument (vlax-get-acad-object)) layers (vla-get-layers acdoc) layerlist '(("A-COLS" 1 "Continuous" 25 "Columns") ("A-BEAM" 2 "Continuous" 30 "Beams") ) ) (foreach x layerlist (setq layer (vla-add layers (car x))) (vla-put-color layer (cadr x)) (vla-put-linetype layer (caddr x)) (vla-put-lineweight layer (cadddr x)) (vla-put-description layer (last x)) ) (princ) )
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
@Jason.Piercey wrote:
@hmsilva wrote:
Well thought out, phanaem! HenriqueExcept it will crash if the linetype does not exist. I suspect the same for the lineweight.
It's true, we have to ensure the linetype exist before applying it, and your suspicions about lineweight are reasoned, if not a valid lineweight...will crash...
Henrique
@Jason.Piercey wrote:
@hmsilva wrote:
Well thought out, phanaem! HenriqueExcept it will crash if the linetype does not exist. I suspect the same for the lineweight.
You are right, and I knew this.
Anyway, defining ltype before layers doesn't solve all the issues. In order to completely set a drawing, many things must be considered, as well as the order of their creation (styles, linetypes, blocks, dimstyle etc). I've simply made a suggestion for solving OP's particular issue.
About lineweight, I'm not so sure... It's user's responsibility to supply a valid value, since it is hard coded. It is done once and for all.
Almost every lisp function will crash if an invalid argument is supplied, yet not every input is checked.
@Jason.Piercey wrote:
Except it will crash if the linetype does not exist. ....
That's one small advantage of doing it with a Layer command. It does not require having the linetype already loaded in the drawing -- it will find it -- and therefore does not require checking whether it is. [Of course, it does have to exist among the available linetypes -- it won't work if, for example, it "does not exist" because it's misspelled, or is a custom linetype that's not present in the system, or something.]