I need to make or find a LISP program that will create a Block for all the entities on each layer of a dwg model file. I have received and imported a model file from a client that contains the geometry for hundreds of objects each separated on individual layers. I'd like to create a block for all the entities on each layer and name the block by the layer name.
Sequence: Activate a layer; select all entities on that layer; create a block from selected entities; save block as layer name; repeat for all layers.
any ideas
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@john.a.latimer wrote:
....
Sequence: Activate a layer; select all entities on that layer; create a block from selected entities; save block as layer name; repeat for all layers.
....
No need to active the Layers in the process. Try something like this [minimally tested]:
(defun C:BCAL ; = Block Contents of All Layers
(/ lyr lyrname)
(tblnext "layer" T); start at 0 [but don't Block it]
(while (setq lyr (tblnext "layer")); each subsequent Layer
(command
"_.block" (setq lyrname (cdr (assoc 2 lyr))) "0,0" (ssget "_X" (list (cons 8 lyrname))) ""
"_.insert" lyrname "_non" "0,0" "" "" ""
"_.chprop" "_last" "" "_layer" lyrname ""
); command
); while
(princ)
); defun
It Inserts because the Block command in a (command) function removes the objects from the drawing.
It could be made to bypass the DEFPOINTS Layer if that's appropriate, or any other specific Layers you may want, and/or could Insert them all on Layer 0 or something, and could use the usual other enhancements, but first see whether it does what you want.
Absolutely Perfect. Simple test proved that it does exactly what I need. Thank you.
Can't find what you're looking for? Ask the community or share your knowledge.