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.
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:
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 -
I've attached another attempt, using someone elses code for a block inserting sub but it still doesn't work...... very confused.....
can you first try to explain what you like to do?
- 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.
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.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.