Hey everyone!
I hope this is a pretty simple question.
I'm working with .NET and am hoping to read a dwg into memory (with C#):
Database database = new Database(false, true); database.ReadDwgFile("C:\\mydrawing.dwg", FileOpenMode.OpenForReadAndReadShare, false, null);
Anyways, I'm familiar with using SelectionSets to access multiple blocks of the same type, or any entities that can be filitered together.
Here is what I wanted to know:
When I work with a database that is stored in memory and not displayed on the editor, should I use SelectionSets?
My original thought was that this is the only way to do what I want to accomplish, however, as I start to think more about it, I'm thinking that I can just search the database for the blocks I want (without using a selectionset).
So, is it possible to going inside the database and only work with a specific block type? And also, how would be the correct way to go about it?
I know in AutoCAD for VBA it takes a long time to iterate through all the Entities in a drawing. So when I use .NET, is there a fast way to look at only the blocks that I care about?
I appreciate the help!
Thanks,
-Nicholas
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
While working with a side database, you cannot use selection sets which require the database to be opened in the editor (selection set methods are methods of the Editor class).
If you're looking for block references you know the name, you can avoid iterating the whole database and find all the references of this block using the BlockTableRecord.GetBlockReferenceIds() method (and the BlockTableRecord.GetAnonymousBlockIds() first if the block is dynamic).
Thanks much! That is exactly what I was looking to know.
Not sure if this is the proper way of choosing the correct BlockTableRecord, but I used:
BlockTableRecord blockDefinition = (BlockTableRecord)transaction.GetObject(blockTable["my_block_name"], OpenMode.ForRead);
Assuming transaction and blockTable are properly initialized Transaction and BlockTable objects, respectively.
The code posted seems to work well!