Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP to Create Block for all entities on each layer in a dwg model file

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
john.a.latimer
1427 Views, 2 Replies

LISP to Create Block for all entities on each layer in a dwg model file

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

 

Labels (3)
2 REPLIES 2
Message 2 of 3


@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.

Kent Cooper, AIA
Message 3 of 3

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.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report