hanskes Posted August 30, 2019 Share Posted August 30, 2019 I am looking for a script that can change the layer of an entity. It must be checked if the layer name ends with -I -W or -E and change to eg same-layername-W, if the layer does not end with -I, -W or -E the entire layer name must be changed to architectural-W. If a layer does not exist, it must be created and the color of layers ending with -W is always 10. A same script for changing to -I (color 7) and to -E (color 102). Any thoughts?. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted August 30, 2019 Share Posted August 30, 2019 (edited) Have you searched for renaming layers? This is a very common question. See if you can find something close and maybe someone will help. Google @ Here Google @ TheSwamp Google @ erwhere Edited August 30, 2019 by ronjonp Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 2, 2019 Author Share Posted September 2, 2019 I have done that. I am not a programmer so it is not easy to stick the right pieces of code together .. I have found this and modified it, but the other entities (that do not meet (-4 . "<or")(8 . "*?-I") (8 . "*?-W") (8 . "*?-E") (-4 . "or>") ) must be renamed to architectural-W, and this succeeds not me. code i have: (defun c:laag-E ( / enx idx lay sel e i l n s x ) (if (setq sel (ssget "_:L" '((-4 . "<or")(8 . "*?-I") (8 . "*?-W") (8 . "*?-E") (-4 . "or>") ))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (substr (cdr lay) 1 (- (strlen (cdr lay)) 2)))) lay enx)) ) ) (if (setq s (ssget "_P" '((8 . "~*-E")))) (repeat (setq i (sslength s)) (setq x (entget (ssname s (setq i (1- i)))) l (assoc 8 x) n (strcat (cdr l) "-E") ) (if (not (tblsearch "layer" n)) (progn (setq e (entget (tblobjname "layer" (cdr l)))) (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 102) (assoc 62 e) e))) ) ) (entmod (subst (cons 8 n) l x)) ) ) (princ) (command "_purge" "la" "" "n") ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 3, 2019 Share Posted September 3, 2019 Is it worth running a BYlayer on all the objects before changing name. Then only change the layer table. No sample dwg to look at. Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 4, 2019 Author Share Posted September 4, 2019 Good point! Changed the code. Any thoughts about the other entities (that do not match ( (-4 . "<or")(8 . "*?-I") (8 . "*?-W") (8 . "*?-E") (-4 . "or>") ) and must be renamed to architectural-W? I don't know how to achieve that. (defun c:laag-E ( / enx idx lay sel e i l n s x ) (command "._CHANGE" (ssget "_:L" ) "" "Properties" "Color" "256" "") (if (setq sel (ssget "_P" '((-4 . "<or")(8 . "*?-I") (8 . "*?-W") (8 . "*?-E") (-4 . "or>") ))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (substr (cdr lay) 1 (- (strlen (cdr lay)) 2)))) lay enx)) ) ) (if (setq s (ssget "_P" '((8 . "~*-E")))) (repeat (setq i (sslength s)) (setq x (entget (ssname s (setq i (1- i)))) l (assoc 8 x) n (strcat (cdr l) "-E") ) (if (not (tblsearch "layer" n)) (progn (setq e (entget (tblobjname "layer" (cdr l)))) (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 102) (assoc 62 e) e))) ) ) (entmod (subst (cons 8 n) l x)) ) ) (princ) (command "_purge" "la" "" "n") ) Quote Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 4, 2019 Share Posted September 4, 2019 (edited) On 8/30/2019 at 12:00 AM, hanskes said: It must be checked if the layer name ends with -I -W or -E The filter you want for this looks like this: (setq s (ssget "_X" '((8 . "*-[IWE]")))) And the opposite of the filter above is this: (setq s (ssget "_X" '((8 . "~*-[IWE]")))) Edited September 4, 2019 by ronjonp Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 4, 2019 Author Share Posted September 4, 2019 ssget "_X" makes a selection of all entities in a drawing. I want to select entities myself and then rename layers of those entities that end with -I, -W or -E differently from entities whose layer name does not end with -I, -W or -E. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 4, 2019 Share Posted September 4, 2019 3 minutes ago, hanskes said: ssget "_X" makes a selection of all entities in a drawing. I want to select entities myself and then rename layers of those entities that end with -I, -W or -E differently from entities whose layer name does not end with -I, -W or -E. Yes I know that but the filter is still relevant. If you want to do this in one selection you'll need to open up the filter and apply the logic within the loop. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 4, 2019 Share Posted September 4, 2019 On 8/30/2019 at 12:00 AM, hanskes said: if the layer name ends with -I -W or -E and change to eg same-layername-W Does this mean you are changing -I and -E to -W ? Or is it SameName-I, SameName-E & SameName-W ? So in the end your drawing should only have 4 layers total ( assuming no xrefs and not counting layer 0 or defpoints )? Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 4, 2019 Author Share Posted September 4, 2019 There are many different layers in a dwg that end with -i or -e or -w (or none of these, usually imported layers from another dwg). Layers ending in -w represent changes made by buyers of a home. layers ending in -e are for additions and -i for information purposes. It often happens that entities are changed during the process from, for example, -i to -w. I want to make a simple button for this. The selected items that do not have one of these suffix must be given a completely new name, for example architectural-w. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 4, 2019 Share Posted September 4, 2019 Try this .. does not do anything for color of layers -I or -E since we're changing them all to -W (defun c:foo (/ el jl n nn s) ;; RJP » 2019-09-04 (cond ((setq s (ssget ":L")) (setq jl "Architectural-W") (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (cond ((wcmatch (strcase (setq n (cdr (assoc 8 (setq el (entget x)))))) "*-[IEW]") (entmod (append el (list (cons 8 (setq nn (strcat (substr n 1 (1- (strlen n))) "W")))))) (entmod (append (entget (tblobjname "layer" nn)) '((62 . 10)))) ) ((entmod (append el (list (cons 8 jl))))) ) ) (and (setq el (tblobjname "layer" jl)) (entmod (append (entget el) '((62 . 10))))) ) ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 7, 2019 Author Share Posted September 7, 2019 (edited) exactly what I was looking for, thanks !! Is it possible to also change the color of the selected entities to bylayer? Edited September 7, 2019 by hanskes Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 7, 2019 Author Share Posted September 7, 2019 found it out: (defun c:laag-w (/ el jl n nn s) ;; RJP » 2019-09-04 (command "._CHANGE" (ssget "_:L" ) "" "Properties" "Color" "256" "") (cond ((setq s (ssget "_P")) (setq jl "00-bouwkundig-W") (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (cond ((wcmatch (strcase (setq n (cdr (assoc 8 (setq el (entget x)))))) "*-[IEW]") (entmod (append el (list (cons 8 (setq nn (strcat (substr n 1 (1- (strlen n))) "W")))))) (entmod (append (entget (tblobjname "layer" nn)) '((62 . 10)))) ) ((entmod (append el (list (cons 8 jl))))) ) ) (and (setq el (tblobjname "layer" jl)) (entmod (append (entget el) '((62 . 10))))) ) ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 12, 2019 Share Posted September 12, 2019 On 9/7/2019 at 1:50 PM, hanskes said: found it out: (defun c:laag-w (/ el jl n nn s) ;; RJP » 2019-09-04 (command "._CHANGE" (ssget "_:L" ) "" "Properties" "Color" "256" "") (cond ((setq s (ssget "_P")) (setq jl "00-bouwkundig-W") (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (cond ((wcmatch (strcase (setq n (cdr (assoc 8 (setq el (entget x)))))) "*-[IEW]") (entmod (append el (list (cons 8 (setq nn (strcat (substr n 1 (1- (strlen n))) "W")))))) (entmod (append (entget (tblobjname "layer" nn)) '((62 . 10)))) ) ((entmod (append el (list (cons 8 jl))))) ) ) (and (setq el (tblobjname "layer" jl)) (entmod (append (entget el) '((62 . 10))))) ) ) (princ) ) (vl-load-com) Glad you got it sorted .. it can also be done like so: (defun c:foo (/ el jl n nn s) ;; RJP » 2019-09-04 (cond ((setq s (ssget ":L")) (setq jl "Architectural-W") (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (entmod (append (entget x) '((62 . 256)))) (cond ((wcmatch (strcase (setq n (cdr (assoc 8 (setq el (entget x)))))) "*-[IEW]") (entmod (append el (list (cons 8 (setq nn (strcat (substr n 1 (1- (strlen n))) "W")))))) (entmod (append (entget (tblobjname "layer" nn)) '((62 . 10)))) ) ((entmod (append el (list (cons 8 jl))))) ) ) (and (setq el (tblobjname "layer" jl)) (entmod (append (entget el) '((62 . 10))))) ) ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
hanskes Posted September 20, 2019 Author Share Posted September 20, 2019 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.