PDA

View Full Version : Insert all Blocks in a drawing file at the same time


BCrouse
2006-03-17, 02:09 PM
Is there a lisp that will allow you to insert all the blocks the are in a drawing at once? The reason that I want to do is to have a way to see all the blocks that are in the dwg.

Thank you,

Brad

kennet.sjoberg
2006-03-17, 03:42 PM
Have you tested [ Ctrl ] 2 ?

: ) Happy Computing !

kennet

BCrouse
2006-03-17, 03:47 PM
Have you tested [ Ctrl ] 2 ?

: ) Happy Computing !

kennet
Yes I have. It does not do what i want it to do.

jwanstaett
2006-03-17, 05:04 PM
If the drawing is open use the purge command and select view items you cannot purge. if AutoCAD did not removed to option after 2002.

Or use the rename command will all so show name of all blocks.

what is it about the [ Ctrl ] 2 (designCenter) that dose not work for you it show all block name of all block in any drawing open or not.

????? Do you what to show where even block is inserted in the drawing not just what the names of the blocks that are defined in the drawing????

BCrouse
2006-03-17, 11:17 PM
I know that you can view the names via purge, rename and the design center. What I would like to do is to insert all the blocks that are in the drawing. Another words to phsically see all the blocks.

Thank you,

Brad

miff
2006-03-17, 11:24 PM
I still don't know what you are missing, then. Desgin Center lets you view (see) the blocks. To do what you are thinking would require a lot of foresight to know WHERE to insert each block. I mean, you probably don't want them all at 0,0,0......so where would you want them inserted?

BCrouse
2006-03-17, 11:30 PM
The main reason for this request is to help to get the blocks. The blocks are not in our block library. They are just floating around collecting digi dust. By having all of them visible on screen. It would help me figure out which blocks that I need to put in the Library. There are over 300 blocks that are in this file and I want find the quickest way to see them and decide on them.

T.Willey
2006-03-18, 12:29 AM
This will insert all the blocks, and prompt you to add them to a list, default is yes. Erase all the objects in the space you are in, and then run. It will turn on all layers, and thaw them. It will return a list of all the blocks you wanted to keep.

(defun InsertAllBlocks (/ AcadObj ActDoc CurSpace LstPt cnt tmpBlk ll ur lr ul Pty tmpPt BlkList)

(vl-load-com)
(setq AcadObj (vlax-get-Acad-Object))
(setq ActDoc (vla-get-ActiveDocument AcadObj))
(vlax-for Lay (vla-get-Layers ActDoc)
(if (not (equal Lay (vla-get-ActiveLayer ActDoc)))
(progn
(vla-put-LayerOn Lay :vlax-true)
(vla-put-Freeze Lay :vlax-false)
)
)
)
(setq CurSpace
(vlax-get ActDoc
(if
(and
(= (vla-get-ActiveSpace ActDoc) 0)
(= (vla-get-MSpace ACtDoc) :vlax-false)
)
'PaperSpace
'ModelSpace
)
)
)
(setq LstPt '(0.0 0.0 0.0))
(setq cnt 1)
(vlax-for Blk (vla-get-Blocks ActDoc)
(if
(and
(= (vla-get-IsXref Blk) :vlax-false)
(= (vla-get-IsLayout Blk) :vlax-false)
(not (vl-string-search "|" (vla-get-Name Blk)))
)
(progn
(setq tmpBlk
(vlax-invoke
CurSpace
'InsertBlock
'(0.0 0.0 0.0)
(vla-get-Name Blk)
1.0
1.0
1.0
0.0
)
)
(vlax-invoke AcadObj 'ZoomExtents)
(initget "Yes No")
(if (/= (getkword (strcat "\n Add \"" (vla-get-Name Blk) "\" block to keeping list [<Y>es No]: ")) "No")
(print (length (setq BlkList (cons (vla-get-Name Blk) BlkList))))
)
(vla-Delete tmpBlk)
)
)
)
BlkList
)

BCrouse
2006-03-18, 01:09 AM
This will insert all the blocks, and prompt you to add them to a list, default is yes. Erase all the objects in the space you are in, and then run. It will turn on all layers, and thaw them. It will return a list of all the blocks you wanted to keep.

(defun InsertAllBlocks (/ AcadObj ActDoc CurSpace LstPt cnt tmpBlk ll ur lr ul Pty tmpPt BlkList)

(vl-load-com)
(setq AcadObj (vlax-get-Acad-Object))
(setq ActDoc (vla-get-ActiveDocument AcadObj))
(vlax-for Lay (vla-get-Layers ActDoc)
(if (not (equal Lay (vla-get-ActiveLayer ActDoc)))
(progn
(vla-put-LayerOn Lay :vlax-true)
(vla-put-Freeze Lay :vlax-false)
)
)
)
(setq CurSpace
(vlax-get ActDoc
(if
(and
(= (vla-get-ActiveSpace ActDoc) 0)
(= (vla-get-MSpace ACtDoc) :vlax-false)
)
'PaperSpace
'ModelSpace
)
)
)
(setq LstPt '(0.0 0.0 0.0))
(setq cnt 1)
(vlax-for Blk (vla-get-Blocks ActDoc)
(if
(and
(= (vla-get-IsXref Blk) :vlax-false)
(= (vla-get-IsLayout Blk) :vlax-false)
(not (vl-string-search "|" (vla-get-Name Blk)))
)
(progn
(setq tmpBlk
(vlax-invoke
CurSpace
'InsertBlock
'(0.0 0.0 0.0)
(vla-get-Name Blk)
1.0
1.0
1.0
0.0
)
)
(vlax-invoke AcadObj 'ZoomExtents)
(initget "Yes No")
(if (/= (getkword (strcat "\n Add \"" (vla-get-Name Blk) "\" block to keeping list [<Y>es No]: ")) "No")
(print (length (setq BlkList (cons (vla-get-Name Blk) BlkList))))
)
(vla-Delete tmpBlk)
)
)
)
BlkList
)





Tim,

Thank you! I will try this on Monday!

Thank you,

Brad

ccowgill
2006-05-25, 06:24 PM
since this is pretty much on the same topic, is there a way to insert multiple blocks from a folder into one drawing.

Right now all of our blocks are individual inside of a folder, I would like to create drawings for different groupings and insert all the blocks that pertain to that group (i.e. cover maps). that way I can create a tool palette from a drawing, and set it up for when we eventually upgrade to a version that uses dynamic blocks.

T.Willey
2006-05-25, 06:42 PM
Are you talking about having a folder, say with 20 files. Then you have four groups, with five drawings each. You want to just select which group you want to add to the current drawings, and it will all those drawings the block collection? I wouldn't think that would be too hard. You may just need a database (or cvs) file so that you know which blocks are inserted per group selected. I would think this can be done with ObjectDBX, or just with inserting each one, and then canceling it before is gets inserted.

Just talking out loud right now.

Opie
2006-05-25, 06:47 PM
Are you talking about having a folder, say with 20 files. Then you have four groups, with five drawings each. You want to just select which group you want to add to the current drawings, and it will all those drawings the block collection? I wouldn't think that would be too hard. You may just need a database (or cvs) file so that you know which blocks are inserted per group selected. I would think this can be done with ObjectDBX, or just with inserting each one, and then canceling it before is gets inserted.

Just talking out loud right now.
Why not insert the group of blocks into a new drawing and save that new drawing with your group name. You could then insert that new drawing from the Design Center, or you could create a Tool Palette with the blocks that are in that drawing. You can also create a Tool Palette from a directory of drawings.

T.Willey
2006-05-25, 07:14 PM
Why not insert the group of blocks into a new drawing and save that new drawing with your group name. You could then insert that new drawing from the Design Center, or you could create a Tool Palette with the blocks that are in that drawing. You can also create a Tool Palette from a directory of drawings.
I was also thinking along those lines. I went with the database idea for updating reasons. I don't use tool palettes, so I don't know if they are useful or not. Good points though.

ccowgill
2006-05-25, 09:02 PM
Why not insert the group of blocks into a new drawing and save that new drawing with your group name. You could then insert that new drawing from the Design Center, or you could create a Tool Palette with the blocks that are in that drawing. You can also create a Tool Palette from a directory of drawings.
what you are suggesting is exactly what I want to do. the problem is all the blocks are in individual drawings.

I have as many as 50 blocks that need to be in these block library drawings, with over 200 total. I am just trying to avoid needing to drag and drop each one individually. What I am intending is, I would like to highlight multiple drawings and drag and drop, or insert them all at the same time into one drawing, at this point I dont care about the insertion point. If it is not possible, I can manually insert each one individually, but I would really prefer not to.

when I try to do it by directory, it crashes because I am trying to add over 200 blocks

T.Willey
2006-05-25, 09:40 PM
You can try this.


(defun c:AddToBlockCol (/ ocmd DirPath DwgList DiaRtn tmpList tmpName)

(setq ocmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(if
(and
(setq DirPath (Directory-Dia "Select directory of drawing files/"))
(setq DwgList (vl-directory-files DirPath "*.dwg" 1))
(setq DwgList (vl-sort DwgList '(lambda (a b) (< (strcase a) (strcase b)))))
(setq DiaRtn (MultiSelect DwgList "Select toggle to add all." T))
(if (/= (car DiaRtn) T)
(progn
(foreach Num DiaRtn
(setq tmpList (cons (nth Num DwgList) tmpList))
)
(setq DwgList tmpList)
)
T
)
)
(foreach BlkName DwgList
(if (tblsearch "Block" (setq tmpName (vl-filename-base BlkName)))
(progn
(command "_.insert" (strcat tmpName "=" DirPath BlkName))
(command)
)
(progn
(command "_.insert" (strcat DirPath BlkName))
(command)
)
)
)
)
(princ)
(setvar "cmdecho" ocmd)
)
;--------------------------------------------------------------------------------------
(defun Directory-Dia ( Message / sh folder folderobject result)
;; By Tony Tanzillo
;; Modified by Tim Willey

(vl-load-com)
(setq sh
(vla-getInterfaceObject
(vlax-get-acad-object)
"Shell.Application"
)
)


(setq folder
(vlax-invoke-method
sh
'BrowseForFolder
(vla-get-HWND (vlax-get-Acad-Object))
Message
0
)
)
(vlax-release-object sh)


(if folder
(progn
(setq folderobject
(vlax-get-property folder 'Self)
)
(setq result
(vlax-get-property FolderObject 'Path)
)
(vlax-release-object folder)
(vlax-release-object FolderObject)
(if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result
)
)
)
)
;--------------------------------------------------------------------------
(defun MultiSelect (Listof Message Toggle / DiaLoad tmpStr tmpTog tmpList)

(setq DiaLoad (load_dialog "MyDialogs.dcl"))
(if (new_dialog "MultiSelect" DiaLOad)
(progn
(start_list "listbox" 3)
(mapcar 'add_list Listof)
(end_list)
(if Message
(set_tile "text1" Message)
)
(if (not Toggle)
(mode_tile "toggle1" 1)
)
(mode_tile "listbox" 2)
(action_tile "accept"
"(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (= (start_dialog) 1)
(progn
(setq tmpList (read (strcat "(" tmpStr ")")))
(if (= tmpTog "1")
(cons T tmpList)
tmpList
)
)
)
)
)
)

ccowgill
2006-05-25, 09:52 PM
that was exactly what I am looking for, it will save me tons of time, thanks.

T.Willey
2006-05-25, 09:54 PM
that was exactly what I am looking for, it will save me tons of time, thanks.
You're welcome. Just be aware that some people say that the list box of dcl's are limited to 255 items.

vferrara
2007-01-15, 07:58 PM
Hello Tim,

I had a need to insert an entire directory of drawing files (blocks) into a drawing. I searched the Forums and found this Thread that looked like it would do exactly what I needed to accomplish. However, when I run the routine I can select a folder of drawings (blocks) and it does bring the blocks into the drawing but it does not insert them on the drawing. Am I doing something incorrectly....??

Any suggestions would be appreciated....!

Regards,
Vince

ccowgill
2007-01-15, 11:17 PM
I do not believe that it is intended to actually insert the blocks, it just adds the block definition to the drawing. When I used it, it performed as I desired it, it added the blocks to the drawing, without inserting them (saves on Regen time for the drawing) I can edit them individually by using the block editor. I would say you are doing nothing incorrectly

T.Willey
2007-01-15, 11:38 PM
Hello Tim,

I had a need to insert an entire directory of drawing files (blocks) into a drawing. I searched the Forums and found this Thread that looked like it would do exactly what I needed to accomplish. However, when I run the routine I can select a folder of drawings (blocks) and it does bring the blocks into the drawing but it does not insert them on the drawing. Am I doing something incorrectly....??

Any suggestions would be appreciated....!

Regards,
Vince

I do not believe that it is intended to actually insert the blocks, it just adds the block definition to the drawing. When I used it, it performed as I desired it, it added the blocks to the drawing, without inserting them (saves on Regen time for the drawing) I can edit them individually by using the block editor. I would say you are doing nothing incorrectly
x2 (man I have to have more letters in my reply, so this is it!)

vferrara
2007-01-16, 01:18 PM
Chris and Tim:

Thank you for your quick response.....this is a great routine just to bring multiple block definitions into the drawing database automatically.

How difficult would it be (if it could be done) to get me started in the right direction, so I could try to add the blocks into the drawing even if they were all inserted at the 0,0 location....??

Thanks again for you help....!

Regards,
Vince

T.Willey
2007-01-16, 05:05 PM
Vince,
This part of the code is what you would change.

(foreach BlkName DwgList
(if (tblsearch "Block" (setq tmpName (vl-filename-base BlkName)))
(progn
(command "_.insert" (strcat tmpName "=" DirPath BlkName))
(command)
)
(progn
(command "_.insert" (strcat DirPath BlkName))
(command)
)
)
)

See how it issues the 'insert' command, and then after it gets the name of the block, there is a call to '(command)'. What this is doing in essence is canceling the insert command, so that it will only insert the block into the block collection, if you wanted to insert the block, then just take out the '(command)' in each part of the 'if' statement, and finish off the 'insert' command in both.

Hope that makes sense.

gilsoto13
2009-10-03, 12:21 AM
Chris and Tim:

Thank you for your quick response.....this is a great routine just to bring multiple block definitions into the drawing database automatically.

How difficult would it be (if it could be done) to get me started in the right direction, so I could try to add the blocks into the drawing even if they were all inserted at the 0,0 location....??

Thanks again for you help....!

Regards,
Vince


We can now use Blkimport.lsp (Bi.lsp).. to insert all the drawings from a directory in the current file, The files will be inserted in a horizontal array with a gap between them.. (inside the lisp file you can change the gap currently at 5.0 units)