MikeP Posted September 29, 2011 Posted September 29, 2011 I would like to be able to have this ask me if I would like to make the new layer the current layer. How do I do this? (defun c:nl ( / name color ) (while (or (not (snvalid (setq name (getstring t "\nSpecify Layer Name: ")))) (tblsearch "LAYER" name) ) (princ "\nLayer Name Invalid or Already Exists.") ) (if (setq color (acad_colordlg 7 nil)) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 70 0) (cons 62 color) ) ) ) (princ) ) Quote
Lt Dan's legs Posted September 29, 2011 Posted September 29, 2011 (initget 1 "Yes No") (getkword "\nYes or no? ") Quote
alanjt Posted September 29, 2011 Posted September 29, 2011 (initget "Yes No") (getkword "\nSet newly created layer as current? [Yes/No]: ") Quote
MikeP Posted September 29, 2011 Author Posted September 29, 2011 ok but now that its ask for that. how do i make it actually set the layer? Quote
alanjt Posted September 29, 2011 Posted September 29, 2011 (initget "Yes No") (if (eq (getkword "\nSet newly created layer as current? [Yes/No] <No>: ") "Yes") (setvar 'CLAYER name) ) Quote
MikeP Posted September 29, 2011 Author Posted September 29, 2011 great thanks. what is the "EQ" used for though? Quote
alanjt Posted September 29, 2011 Posted September 29, 2011 great thanks. what is the "EQ" used for though? It's comparing to see if the result returned from getkword is equal to the "Yes" string I have at the end. Quote
MikeP Posted September 29, 2011 Author Posted September 29, 2011 ok thanks. I understand. If you guys might find this helpful. Hereis the final lisp. I added a command in the end to be easily set the layer back to 0, if needed. thanks (defun c:nl ( / name color ) (while (or (not (snvalid (setq name (getstring t "\nSpecify Layer Name: ")))) (tblsearch "LAYER" name) ) (princ "\nLayer Name Invalid or Already Exists.") ) (if (setq color (acad_colordlg 7 nil)) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 70 0) (cons 62 color) ) ) ) (initget "Yes No") (if (eq (getkword "\nSet newly created layer as current? [Yes/No] <No>: ") "Yes") (setvar 'CLAYER name) ) (princ) ) (defun C:l0 () (setvar 'CLAYER "0") (princ) ) Quote
alanjt Posted September 29, 2011 Posted September 29, 2011 I use the following... ;MAKE A LAYER (defun c:LM () (command "-layer" "make" ) (princ)) (defun AT:DummyLayer (name color plot / ss) (setq ss (ssget "_I")) (cond ((eq (strcase name) (strcat (getvar 'clayer))) (princ (strcat "\nLayer: \"" name "\" is the current layer.")) ) ((tblsearch "layer" name) (vl-cmdf "_.layer" "_t" name "_s" name "_p" plot name "") (princ (strcat "\nLayer: \"" name "\" is the current layer.")) ) ((vl-cmdf "_.layer" "_m" name "_c" color name "_p" plot name "") (princ (strcat "\nLayer: \"" name "\" has been created.")) ) ) (if ss ((lambda (i / e) (while (setq e (ssname ss (setq i (1+ i)))) (vla-put-layer (vlax-ename->vla-object e) name) ) (princ (strcat "\n" (itoa (sslength ss)) " object(s) moved to layer: \"" name "\"")) ) -1 ) ) ) ;"ALAN" LAYER (defun c:ALAN (/) (AT:DummyLayer "ALAN" 2 "P") (princ)) ;"TEMP" LAYER (defun c:TEMP (/) (AT:DummyLayer "TEMP" 7 "P") (princ)) ;"DEFPOINTS" LAYER (defun c:DEF (/) (AT:DummyLayer "Defpoints" 7 "N") (princ)) ;"VP" LAYER (defun c:VP (/) (AT:DummyLayer "VP" 4 "N")(princ)) ;"HIDE" LAYER (defun c:HI (/) (AT:DummyLayer "HIDE" 210 "N")(princ)) ;"0" LAYER (defun c:L0 (/) (AT:DummyLayer "0" 7 "P")(princ)) The AT: DummyLayer is sloppy but for something simple like this, it does the trick - I also did this a long time ago. The nice thing is, if you have anything selected when you issue a command using the AT: DummyLayer sub, it will place those objects on that layer. Quote
MikeP Posted September 29, 2011 Author Posted September 29, 2011 hmm, I really like it to be able to set the current selected object to the new layer. how could I incorporate that part from yours into what I have in mine? Quote
alanjt Posted September 29, 2011 Posted September 29, 2011 hmm, I really like it to be able to set the current selected object to the new layer. how could I incorporate that part from yours into what I have in mine? Take the selection line at the beginning and the selection set processing at the end. Quote
MikeP Posted September 29, 2011 Author Posted September 29, 2011 cant believe its working (im new to lisp) thanks alot Quote
alanjt Posted September 29, 2011 Posted September 29, 2011 cant believe its working (im new to lisp) thanks alot No problem. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.