Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I change a default answer within the Layer Command?

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
perkins76
527 Views, 13 Replies

How do I change a default answer within the Layer Command?

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.

 

13 REPLIES 13
Message 2 of 14
smaher12
in reply to: perkins76

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)
)

 

Message 3 of 14
Kent1Cooper
in reply to: perkins76

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.

Kent Cooper, AIA
Message 4 of 14
smaher12
in reply to: Kent1Cooper

My apologizes, I misunderstood the post.

Message 5 of 14
dbroad
in reply to: perkins76

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" "")
)

 

Architect, Registered NC, VA, SC, & GA.
Message 6 of 14
hmsilva
in reply to: perkins76


@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

EESignature

Message 7 of 14
phanaem
in reply to: perkins76

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)
)

 

Message 8 of 14
scot-65
in reply to: phanaem

Nice!
Since there are multiple items in the list, I would use the following:
(setq layer (vla-add layers (nth 0 x)))
...
(vla-put-description layer (nth 4 x))

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 9 of 14
hmsilva
in reply to: phanaem

Well thought out, phanaem! Henrique

EESignature

Message 10 of 14
perkins76
in reply to: phanaem

This completely worked! Way above my skill level, so thank you very much for your help!
Message 11 of 14
Jason.Piercey
in reply to: hmsilva


@hmsilva wrote:
Well thought out, phanaem! Henrique

Except it will crash if the linetype does not exist.  I suspect the same for the lineweight.

Message 12 of 14
hmsilva
in reply to: Jason.Piercey


@Jason.Piercey wrote:

@hmsilva wrote:
Well thought out, phanaem! Henrique

Except 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

 

EESignature

Message 13 of 14
phanaem
in reply to: Jason.Piercey


@Jason.Piercey wrote:

@hmsilva wrote:
Well thought out, phanaem! Henrique

Except 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. 

Message 14 of 14
Kent1Cooper
in reply to: Jason.Piercey


@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.]

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost