jaylo23 Posted December 17, 2008 Share Posted December 17, 2008 Hello and good morning to all (and good afternoon to others). Did a search and could not find what i was looking for so i apologize if this has already been asked but here goes...Looking for a lisp that would prompt the user to select objects, after objects are selected the lisp would take the layers of the selected objects and add "_EX" to the end of the layer name and change the layer color to green. The problem i have is that i have a bunch of equipment xrefs that were modeled using layers such as "eq-bdy" and now need to be shown as existing in our models which is where the "_EX" comes in. Also would like the lisp to ignore entities that are on layer 0 and defpoints if possible. Again i apologize if this has already been discussed and if so please point me in the right direction. Thanks in advance to all. Quote Link to comment Share on other sites More sharing options...
ReMark Posted December 17, 2008 Share Posted December 17, 2008 I doubt you'll find a generic routine that will do exactly what you want. You'll have to find and then modify an existing custom Lisp routine or write a new one. Quote Link to comment Share on other sites More sharing options...
Raggi_Thor Posted December 17, 2008 Share Posted December 17, 2008 Will this work for you? Just copy paste to test quickly: (defun c:LM() ;modfy name as you like, LM is fast to type (command "laymcur" pause) ;set current layer by selecting object (command "layer" "m" (strcat(getvar "clayer") "_EX") "color" "green" " " " ") (princ) ) Quote Link to comment Share on other sites More sharing options...
jaylo23 Posted December 17, 2008 Author Share Posted December 17, 2008 Will this work for you? Just copy paste to test quickly: It seems to be kinda close to what im looking for. It doesnt put the entities on the newly created layers and gives me an error when exiting it. It also doesnt ignore layer 0 but i think i could just write in the lisp to freeze layer 0 and defpoints at the begining and thaw those layers afterwards. But this is alot better than anything i could come up with thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 17, 2008 Share Posted December 17, 2008 I had a go at it, but I don't think I have the knowledge in LISP to accomplish it. I tried modifying it like this: (defun c:sel (/ ent lay lay1) (setq ent (car entsel)) (setq lay (cdr (assoc 8 (entget ent)))) (setq lay1 (tblsearch "layer" lay)) (setq lay1 (subst (cons 2 (strcat lay "_EX")) (assoc 2 lay1) lay1)) (entmod lay1) (princ) ) ;_ end defun But to no avail. Quote Link to comment Share on other sites More sharing options...
jaylo23 Posted December 17, 2008 Author Share Posted December 17, 2008 Thanks anyways for your attempt Lee Mac. Anyone, Would it possible to create an table from the selected objects and maybe use the rename command to put "_EX" at the end of all the layers? Maybe im shooting in the dark! Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 17, 2008 Share Posted December 17, 2008 how about this: wrote it real quick, tested it once. (defun c:layex ( / ssobjlist ss_obj ss_obj_list obj ) ;;;;;SUBROUTINES;;;;; (defun ssobjlist (sset / zaehler objlist) (setq zaehler (1- (sslength sset))) (while (>= zaehler 0) (if (< zaehler (1- (sslength sset))) (setq objlist (cons (ssname sset zaehler) objlist)) (setq objlist (list (ssname sset zaehler))) ) ;Ende if (setq zaehler (1- zaehler)) ) ;Ende While objlist ) ;Ende defun ;;;;;MAIN ROUTINE;;;;; (setq ss_obj (ssget "_:L" '((-4 . "<not")(8 . "0,Defpoints")(-4 . "not>")))) (if ss_obj (progn (command "_.undo" "_begin") (setq ss_obj_list (ssobjlist ss_obj)) (foreach obj ss_obj_list (setq obj_lay (cdr (assoc 8 (entget obj)))) (if (not (wcmatch obj_lay "*_EX")) (progn (command "_.rename" "_la" obj_lay (strcat obj_lay "_EX")) (command "_.layer" "_co" 3 (strcat obj_lay "_EX") "") (princ (strcat "\nLayer \"" obj_lay "\" rename to: \"" obj_lay "_EX\"")) );progn );if );foreach (command "_.undo" "_end") );progn (princ "\nNothing selected, try again") );if (princ) );defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 17, 2008 Share Posted December 17, 2008 Very nice Alan, I didn't know of the rename command - certainly makes things easier! Quote Link to comment Share on other sites More sharing options...
jaylo23 Posted December 17, 2008 Author Share Posted December 17, 2008 That worked great Alan!!!! Many thanks to you and am extremely grateful (so our my CAD operators when they find out about this one). You have made my work month soooooo much better! I gotta about 1000 equipment blocks to use this on! Again, thank you sir! Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 19, 2008 Share Posted December 19, 2008 thanks lee. you're very welcome jaylo, glad it helps. had a few minutes and it was a nice break from creating c3d styles for our switch. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 20, 2008 Share Posted December 20, 2008 By the way, one question: what is the purpose of the "undo" "begin" and "undo" "end"? Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 20, 2008 Share Posted December 20, 2008 By the way, one question: what is the purpose of the "undo" "begin" and "undo" "end"? to combine all the changes into 1 undo mark. if it wasn't there and you decided to undo after selecting 10 items, you would have to undo twice for each item. this way it can be undone with just one "u" Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 20, 2008 Share Posted December 20, 2008 Ahhh, that makes sense. Thanks. Oh, and sorry to bother you further, but I am not sure of this line: (ssget "_:L" '((-4 . "<not")(8 . "0,Defpoints")(-4 . "not>")))) I understand you are retrieving a selection set that you later convert into a list using your subroutine, but after looking into the ACAD help, I do not see an ssget "_:L" and I don't understand how the (-4 . " Also, Just out of interest, is there a way to modify tblsearch entities and update them the way one would with normal DXF tables retrieved via entsel? i.e., is there a way of accomplishing a change of layer name without going into (command "_rename")? Quote Link to comment Share on other sites More sharing options...
wizman Posted December 20, 2008 Share Posted December 20, 2008 ssget "_:L" >>> rejects locked layers (-4 . ">> think of this as an open parenthesis which needs a closing of (-4 . "not>") Also, Just out of interest, is there a way to modify tblsearch entities and update them the way one would with normal DXF tables retrieved via entsel? i.e., is there a way of accomplishing a change of layer name without going into (command "_rename")? lee try (tblnext "LAYER"), i think you know the next steps.....:-) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 20, 2008 Share Posted December 20, 2008 Thanks for your help Wizman, those explanations are pretty good. (so the (-4 . " As for this: lee try (tblnext "LAYER"), i think you know the next steps.....:-) in an earlier post, I tried this: (defun c:sel (/ ent lay lay1) (setq ent (car entsel)) (setq lay (cdr (assoc 8 (entget ent)))) (setq lay1 (tblsearch "layer" lay)) (setq lay1 (subst (cons 2 (strcat lay "_EX")) (assoc 2 lay1) lay1)) (entmod lay1) (princ) ) ;_ end defun It altered the table entry, but didn't change the layer name.. not sure why? Thanks again for all your help. Quote Link to comment Share on other sites More sharing options...
wizman Posted December 20, 2008 Share Posted December 20, 2008 Lee, i should have said TBLOBJNAME, sorry for confusing: (defun c:sel (/ ent lay lay1) (setq ent (car (entsel))) (setq lay (cdr (assoc 8 (entget ent)))) (setq lay1 (tblsearch "layer" lay)) (setq lay1 (subst (cons 2 (strcat lay "_ex")) (assoc 2 (entget (tblobjname "layer" lay))) (entget (tblobjname "layer" lay)) ) ;_ end_subst ) ;_ end_setq (entmod lay1) (princ) ) ;_ end_defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 20, 2008 Share Posted December 20, 2008 Superb Wizman, works a treat. I always like to break the LISP down to the tbl definitions, instead of just using the in built ACAD commands, like rename. I suppose it means more typing, but I understand the LISP better that way. tblobjname - yet another tool at my disposal - many thanks Quote Link to comment Share on other sites More sharing options...
kalarpu Posted August 21, 2009 Share Posted August 21, 2009 Hi If I want to add _EX only when I select standard layer which is 14 characters (example "A-_1234----_E-"),how to do? And if less than or excess 14 please pop up note (Your layer "----" is not a standard layer format), how to? Thanks a lot! Kalarpu:roll: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2009 Share Posted August 21, 2009 Blimey, this is an old thread... brings back some memories - I've come a long way since then! Try this: (defun c:lay (/ ent Nme) (vl-load-com) (while (setq ent (car (entsel "\nSelect Object on Layer: "))) (setq Nme (cdr (assoc 8 (entget ent)))) (if (= 14 (strlen Nme)) (vla-put-Name (vla-item (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) Nme) (strcat Nme "_EX")) (princ (strcat "\n<< Layer: " Nme " is not Standard Format >>")))) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 21, 2009 Share Posted August 21, 2009 HiIf I want to add _EX only when I select standard layer which is 14 characters (example "A-_1234----_E-"),how to do? And if less than or excess 14 please pop up note (Your layer "----" is not a standard layer format), how to? Thanks a lot! Kalarpu:roll: (and (= (strlen "LAYERNAME") 14) (wcmatch "LAYERNAME" "[AECMV ]-*") ) this would make sure the layername is 14 characters long and has a prefix of "A-", "E-", "C-", "M-" or "V-" (couldn't remember all of them). Quote Link to comment Share on other sites More sharing options...
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.