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

Selection Set or Database or both?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Millerni456
526 Views, 2 Replies

Selection Set or Database or both?

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

2 REPLIES 2
Message 2 of 3
_gile
in reply to: Millerni456

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).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
Millerni456
in reply to: _gile

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! Smiley Wink

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