
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I look for a lisp moving all objects (which are all in the same layer) including those inside blocks in dwg (both model space and all other paper spaces) to another layer (destination layer). Potentially several layers at the same time. For instance, all objects in "Layer01" want to be in "Layer01_New" and all objects in "Layer02" want to be in "Layer02_New" and so on. All layers (original names such as “Layer01”, “Layer02” “…” and destination names such as “Layer01_New”, “Layer02_New”, “…” are all existing. Preferably if the destination names do not exist, it creates those layers. (If this is possible, please let me know how to specify the color and linetype as well when it creates destination layers.) Then, delete the original layers. (Deleting the original layers hopefully will be done with the command below.)
(command "-purge" "la" " Layer01" "n")
(command "-purge" "la" " Layer02" "n")
Highly appreciated for this solution and help. I would like to describe the process I made and issues I came across below so I can make what I need much more sense and easier to understand.
First I found this topic below.
The lisp mentioned in the middle of topic, which might work fine is below. This one worked fine if objects are in the all different spaces (model space and paper spaces). But did not work for objects inside block and especially when objects with the old layer name did not exist in the drawing (it returned “error” and stopped loading other programs.
(command
"_.chprop"
(setq ss (ssget "_X" '((8 . "GREEN"))))
(repeat (sslength ss)
(setq
objdata (entget (ssname ss 0))
objdata (subst '(8 . "PURPLE") '(8 . "GREEN") objdata)
); end setq
(entmod objdata)
(ssdel (ssname ss 0) ss)
); end repeat
)
So, then I tried to look up more and also found the topic below.
This lisp below worked perfect with the objects inside blocks. But it did not change the regular objects outside of blocks, which means this works great only for blocks. And not sure if it worked all objects in the all different spaces (model space and paper spaces)
(vl-load-com)
(defun c:demo (/ put-layer)
(defun put-layer (obj old-lay new-lay / layers olay)
(or *adoc (setq *adoc (vla-get-activedocument (vlax-get-acad-object))))
(setq layers (vla-get-layers *adoc))
(if (vl-catch-all-error-p
(vl-catch-all-apply 'vla-item (list layers new-lay))
)
(progn
(vla-add layers new-lay)
(setq layers (vla-get-layers *adoc))
)
)
(if (= (vla-get-Lock (setq olay (vla-item layers old-lay))) :vlax-true)
(progn
(vla-put-Lock olay :vlax-false)
(vla-put-Layer obj new-lay)
(vla-put-Lock olay :vlax-true)
)
(vla-put-Layer obj new-lay)
)
)
(or *adoc (setq *adoc (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for blk (vla-get-blocks *adoc)
(if (and (= (vla-get-IsXref blk) :vlax-false)
(= (vla-get-IsLayout blk) :vlax-false)
)
(vlax-for x blk
(cond ((= (vla-get-Layer x) "1")
(put-layer x "1" "a")
)
((= (vla-get-Layer x) "2")
(put-layer x "2" "b")
)
((= (vla-get-Layer x) "3")
(put-layer x "3" "c")
)
)
)
)
)
(vla-regen *adoc acAllViewports)
(princ)
)
Solved! Go to Solution.