.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Multiple Blocks Within One DWG

7 REPLIES 7
Reply
Message 1 of 8
Hugh_Compton
872 Views, 7 Replies

Insert Multiple Blocks Within One DWG

I'm trying to get a routine that creates and inserts a copy of all the block entities in a DWG.  For some reason the code causes CAD to hang?  See attachment for code.

 

 

Tags (1)
7 REPLIES 7
Message 2 of 8

Hi,

 

you scan all BlockTableRecords, and within them for all Blockreferences.

Eg. if ModelSpace has a BlockReference included you insert a new BlockReference based on the current one and so you have an endless loop.

With other words:

  • we start with ModelSpace having 1 BlockReference
  • You found it and insert this one in ModelSpace
  • Now you have two BlockRefences in Modelspace
  • Next you make as step forward in your loop and find your second BlockReference
  • From that you create a third one
  • and so on .... endless

 

Back to the roots, what should this code do?

If you want to make a list of all blockdefinitions then just go through your BlockTable, and each BlockTableRecord, that is not of type layout, create a BlockReference in ModelSpace.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 8
Hugh_Compton
in reply to: Hugh_Compton

 

Thanks for the hints.  I've tried to get the block obejct IDs first and then do the inserting afterwards (see attached) but CAD still hangs 😞

Message 4 of 8
Hugh_Compton
in reply to: Hugh_Compton

 

I've attached another attempt, using someone elses code for a block inserting sub but it still doesn't work...... very confused.....

Message 5 of 8

Hi,

 

can you first try to explain what you like to do?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 8
Hugh_Compton
in reply to: Hugh_Compton

Hi Alfred

 

I do schematic drawings that have blocks representing valves / fittings etc.  Once the blocks are in position it is useful to create a legend.  To create the legend I have to insert one of each block in the schematic and then annotate what the block is (I have a tagging routine for the annotations that works well). 

 

I need a routine that will grab one instance of each of the blocks in modelspace and reinsert at a new location selected by me. 

Message 7 of 8

In your revision code, you were still adding items to the blockTableRecord while looping through it.

 

In Attempt 3, all I see is that the dictionary entries are required to be unique.  I am assuming that you have more than one of each block in modelspace, so the second time you find the same block, you are getting a duplicate key exception.

 

you need to test the dictionary contents before adding each Id/name pair.

 

if not dict.ContainsKey(id) then dict.add(id,name)

 

If you are using 2009 or newer AutoCAD, then you could also benefit from using ObjectID.ObjectClass.Name to type test the objects before opening them, instead of opening everything.

Dave O.                                                                  Sig-Logos32.png
Message 8 of 8
David125
in reply to: chiefbraincloud

Super easy, no lisp required. Xref all blocks in at one time on same coordinates and bind them afterward. I do it frequently. 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost