Jump to content

A lisp to insert all blocks in the file


asos2000

Recommended Posts

Some times there is a file has a lot of block but not inserted. but before making a purge i want to see all blocks. So I am searching for a lisp to insert all blocks. like the attached file.

12-17-2009 10-55-17 AM.jpg

Link to comment
Share on other sites

Just put all blocks into ONE BLOCK inside a single DWG file. Then use Tool Palettes or Design Center to bring in that one block and all the others nested inside will come with it, inserting them all at once into your current drawing.

Link to comment
Share on other sites

Here is a quick and dirty way to insert all block definitions in the current drawing.

 


(setq *acad* (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq *ms* (vla-get-ModelSpace *acad*))
(vlax-for
         item
             (vla-get-Blocks *acad*)
 (setq name (vla-get-Name item))  
 (if (not (eq "*" (substr name 1 1)))
   (vlax-invoke-method
     *ms*
     'InsertBlock
     (vlax-3d-point (list 0.0 0.0 0.0))
     (vla-get-Name item)
     1.0
     1.0
     1.0
     0.0
   )
 )
)

  • Like 1
Link to comment
Share on other sites

Thanx

This is what I am looking for.

I made some change for insertion point.

(DEFUN C:BLKINS ()

(setq *acad* (vla-get-ActiveDocument (vlax-get-acad-object)))

(setq *ms* (vla-get-ModelSpace *acad*))

(vlax-for

item

(vla-get-Blocks *acad*)

(setq name (vla-get-Name item))

(if (not (eq "*" (substr name 1 1)))

(vlax-invoke-method

*ms*

'InsertBlock

(vlax-3d-point (getpoint "Pick Point"))

(vla-get-Name item)

1.0

1.0

1.0

0.0

)

)

)

)

 

but I have to pick point for each block. How to use the same point for all blocks

Link to comment
Share on other sites

Try this:

 

(DEFUN C:BLKINS  (/ pt name)
 (vl-load-com)
 
 (setq *acad* (vla-get-ActiveDocument
                (vlax-get-acad-object)))
 (setq *ms*   (vla-get-ModelSpace *acad*))

 (vlax-for item (vla-get-Blocks *acad*)

   (if (and (not (eq "*" (substr (setq name (vla-get-Name item)) 1 1)))
            (setq pt (getpoint "\nSelect Point for Block: ")))
     
     (vlax-invoke-method *ms* 'InsertBlock (vlax-3d-point pt) name 1.0 1.0 1.0 0.0)))

 (princ))

 

EDIT: Sorry, didn't read your last bit

Link to comment
Share on other sites

Try this instead:

 

(DEFUN C:BLKINS  (/ blks pt name)
 (vl-load-com)
 
 (setq *acad* (vla-get-ActiveDocument
                (vlax-get-acad-object)))
 (setq *ms*   (vla-get-ModelSpace *acad*))

 (if (and (not (zerop (- (vla-get-count (setq blks (vla-get-blocks *acad*))) 1 (length (layoutlist)))))
          (setq pt (getpoint "\nSelect Point for Block: ")))

   (vlax-for item blks

     (if (not (eq "*" (substr (setq name (vla-get-Name item)) 1 1)))
       (vlax-invoke-method *ms* 'InsertBlock (vlax-3d-point pt) name 1.0 1.0 1.0 0.0))))

 (princ))

Link to comment
Share on other sites

I would extract them to individual drawings to a specified sirectory using wba.lsp and then I would use Bi (Blkimport.lsp) to insert all those extracted blocks to the current drawing using a gap of 5.0 units between them... you can change the gap inside the lisp.

wba.lsp

BI.lsp

Link to comment
Share on other sites

Thanx RKMCSWAIN

Thanx LEE

There is a question

could the lisp calculate the block width then insert the next block in previous insertion point plus block width.

Link to comment
Share on other sites

Just offering this one, if your purpose is for inspection, give a try also on autocad design center. Type ADC then go to 'open drawings' tab then pick on the 'blocks'. You'll see all the thumbnails in one window. And when you click on one thumbnail, a larger thumbnail is shown below which you can stretch further up so it can be seen having a larger view of the block without even inserting.

 

 

 

Link to comment
Share on other sites

  • 3 years later...

Hai,

is it possible to addapt the lisp command code to create a lisp to insert all blocks with name start with "PL Pan" ?

 

i don't know anything from the code but i used it and its verry practical thanks already! :-D

Link to comment
Share on other sites

  • 10 years later...
On 12/17/2009 at 8:54 AM, Lee Mac said:

I know this is a very very very old thread and lsp routine.  However, is there a way to provide a offset to each block or a table where they could be offset X-dist and Y-dist.  Let's say max of 50 blocks Y and a specific distance of 6" and however many it columns in X it took... there are about 640 blocks in this drawing I want to review.  Right now it inserts them all at same insertion point

On 12/17/2009 at 8:54 AM, Lee Mac said:

 

 

(DEFUN C:BLKINS  (/ blks pt name)
 (vl-load-com)
 
 (setq *acad* (vla-get-ActiveDocument
                (vlax-get-acad-object)))
 (setq *ms*   (vla-get-ModelSpace *acad*))

 (if (and (not (zerop (- (vla-get-count (setq blks (vla-get-blocks *acad*))) 1 (length (layoutlist)))))
          (setq pt (getpoint "\nSelect Point for Block: ")))

   (vlax-for item blks

     (if (not (eq "*" (substr (setq name (vla-get-Name item)) 1 1)))
       (vlax-invoke-method *ms* 'InsertBlock (vlax-3d-point pt) name 1.0 1.0 1.0 0.0))))

 (princ))
 

 

 

Link to comment
Share on other sites

Not sure what your asking for, very old post,  a couple of suggestions can do max X columns or max Y rows, take total number of blocks get sqrt this will make a X & Y, rows & columns equal of blocks.

Link to comment
Share on other sites

  • 3 months later...

This was useful for me:

 

(DEFUN C:BBB (/ blks pt name distance) (vl-load-com) (setq *acad* (vla-get-ActiveDocument (vlax-get-acad-object))) (setq *ms* (vla-get-ModelSpace *acad*)) (if (and (not (zerop (- (vla-get-count (setq blks (vla-get-blocks *acad*))) 1 (length (layoutlist))))) (setq pt (getpoint "\nSelect Point for Block: "))) (progn (setq distance (getreal "\nEnter the distance between blocks: ")) (vlax-for item blks (if (not (eq "*" (substr (setq name (vla-get-Name item)) 1 1))) (progn (vlax-invoke-method *ms* 'InsertBlock (vlax-3d-point pt) name 1.0 1.0 1.0 0.0) (setq pt (mapcar '+ pt (list distance 0.0 0.0)))))))) (princ))

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...