@Anonymous wrote:
... if there's a match of "*EXIST", it runs the function I've written up. ....
....
(setq layOld (getvar "clayer"))
(setq layNew (strcat layOld "-OFF"))
....
(command "-COPYTOLAYER" ss "" layNew "y" "0,0,0" "")
....
I wonder whether you really want the layNew variable like that. If the current Layer when you run the routine happens to be 0, then everything on any Layer whose name contains "EXIST" will be copied onto a Layer called "0-OFF" regardless of what Layer its source object was on. Is that the intent? Wouldn't you want things copied to Layers that are named the same as the Layers the objects are on, with the "-OFF" suffix added? If something's on a Layer called "WALLEXIST1", don't you want it copied onto a Layer called "WALLEXIST1-OFF", rather than to a Layer called "0-OFF", or "Defpoints-OFF", or some other name based on whatever the current Layer happens to be?
If that's the case, here's a different [and look how short!] approach. Don't do it by Layers, but by objects, using (ssget) to find all things on any Layer containing "EXIST" in its name, all at once. Then rather than use COPYTOLAYER, (entmake) a copy of each with a suffixed Layer name.
You don't have to exclude Xref Layers, because (ssget) won't see things on those Layers. And you don't have to check whether a newly-suffixed Layer name exists, because this kind of (entmake (subst....)) approach will create the Layer in the process. And you would need to decide what you want to do about locked Layers -- this doesn't prevent making copies of things on locked Layers, because it doesn't affect those things themselves at all. Mildly tested:
(defun C:TEST (/ ss n edata)
(if (setq ss (ssget "_X" '((8 . "*EXIST*"))))
(repeat (setq n (sslength ss))
(setq edata (entget (ssname ss (setq n (1- n)))))
(entmake (subst (cons 8 (strcat (cdr (assoc 8 edata)) "-OFF")) (assoc 8 edata) edata))
); repeat
); if
(princ)
); defun
But if you really do want the new suffixed Layer name to be based on whatever the current Layer is, and things from all those other Layers copied onto the one common suffixed Layer, just replace
(cdr (assoc 8 edata))
in the above with
(getvar 'clayer)
Kent Cooper, AIA