acad1985 Posted April 21, 2018 Share Posted April 21, 2018 Hello Everyone. I have a Lisp to rename the Layer by Part of Layer name. but the code is not working. (defun C:Test() (if (setq xlay (ssget "_X" '((8 . "*_Proposed_*")))) (command "-layer" "r" xlay "Proposed Entity" "") ) ) I want to select the layers which is having "Proposed" in their Name, then rename to PROPOSED ENTITY. (Layer names like, Region_Proposed_Street, City_Proposed_street) If someone can help me thank you very much. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted April 21, 2018 Share Posted April 21, 2018 Hello Everyone.I have a Lisp to rename the Layer by Part of Layer name. but the code is not working. (defun C:Test() (if (setq xlay (ssget "_X" '((8 . "*_Proposed_*")))) (command "-layer" "r" xlay "Proposed Entity" "") ) ) I want to select the layers which is having "Proposed" in their Name, then rename to PROPOSED ENTITY. (Layer names like, Region_Proposed_Street, City_Proposed_street) If someone can help me thank you very much. Your code isn't working and won't work because: 1. You are trying to pass a selection set to the layer command. 2. The selection set will contain all entities on layers with "Proposed" in the layer name, NOT the layer itself. 3. Your code is attempting to give multiple layers the same name, unless your mean to substitute "Proposed Entity" for "Proposed" in the existing layer name? 1 & 2 are surmountable , but 3 isn't and needs a rethink e.g. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted April 22, 2018 Author Share Posted April 22, 2018 Is there any other way to do this..? Whatever the layers having Proposed in their name. That should be rename to Proposed Entity. Can we done by using Layer merge.? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 22, 2018 Share Posted April 22, 2018 Hi, Just create that new layer name if its already existed then make a selection set of those objects on the old layers then move them to the new layer. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted April 22, 2018 Share Posted April 22, 2018 Is there any other way to do this..?Whatever the layers having Proposed in their name. That should be rename to Proposed Entity. Can we done by using Layer merge.? As per Tharwat's post this should accomplish what you want : (defun c:move2layer ( / *error* c_doc c_lyrs cmde n_lyr ss ss_objs) (defun *error* ( msg ) (if cmde (setvar 'cmdecho cmde)) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred."))) (princ) );_end_*error*_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_lyrs (vla-get-layers c_doc) n_lyr "Proposed Entity" ) (if (/= (getvar 'cmdecho) 0) (progn (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0))) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (vla-startundomark c_doc) (if (not (tblsearch "layer" "Proposed Entity")) (vla-add c_lyrs n_lyr)) (setq ss (ssget "_X" '((8 . "*_Proposed_*")))) (if ss (setq ss_objs (vla-get-activeselectionset c_doc))) (vlax-for obj ss_objs (vlax-put obj 'Layer n_lyr) ) (setq ss nil ss_objs nil ) (if cmde (setvar 'cmdecho cmde)) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) );end_defun Type "move2layer" to run It will move all objects on layers with "_Proposed_" in their name into a layer called "Proposed Entity". If the layer doesn't exist it will create it. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted April 23, 2018 Author Share Posted April 23, 2018 Hi Tharwat Thanks for your reply.. Just create that new layer name if its already existed then make a selection set of those objects on the old layers then move them to the new layer. Could you please tell me how to do this.? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 23, 2018 Share Posted April 23, 2018 Hi TharwatThanks for your reply.. Could you please tell me how to do this.? Hi, Be sure to have objects on unlocked layers in prior of invoking / running the following routine. (defun c:Test ( / s i o e) (and (setq i -1 s (ssget "_X" '((8 . "*_Proposed_*")))) (while (setq o (ssname s (setq i (1+ i)))) (entmod (subst '(8 . "Proposed Entity") (assoc 8 (setq e (entget o))) e))) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
acad1985 Posted April 23, 2018 Author Share Posted April 23, 2018 Thank you so much Tharwat.. It's worked perfectly. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 23, 2018 Share Posted April 23, 2018 You are welcome anytime. 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.