Hello.
Does anyone know how I can get all the "Block Reference" from the drawing
Now I'm doing it like that ...
C#
public void GetBlkRef() { foreach (AcadEntity Entity in ThisDrawing.ModelSpace) { if (Entity.ObjectName == "AcDBlockreference") { } } }
or
VB.NET
Public Sub GetBlkRef() For Each Entity As AcadEntity In ThisDrawing.ModelSpace If Entity.ObjectName = "AcDBlockreference" Then End If Next End Sub
but this method works slowly on large drawings.
How can I get quick access to all "AcDbBlockReference" objects?
Is there a collection with all the objects of "AcDbBlockReference"?
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by _gile. Go to Solution.
Hi,
if using the COM API is not mandatory, you can try using a filtered selection set (but I'm not certain it's faster, the model space have to be iterated anyway).
// build the selection filter short[] filterType = { 0, 410 }; object[] filterData = { "INSERT", "Model" }; // create the selection set AcadSelectionSet selectionSet = thisDrawing.SelectionSets.Add("SSET"); // select all block references in model space selectionSet.Select(AcSelect.acSelectionSetAll, Type.Missing, Type.Missing, filterType, filterData); // iterate through the selection set foreach (AcadBlockReference block in selectionSet) { // do your stuff with selected blocks block.Layer = "1"; } // delete the selection set selectionSet.Delete();
If you could use the .NET API, iterating through the model space should be faster because you could check for the entity type directly from its ObjectId.
// get the working database var db = HostApplicationServices.WorkingDatabase; // start a transaction using (var tr = db.TransactionManager.StartTransaction()) { // open the model space for read var modelSpace = (BlockTableRecord)tr.GetObject( SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead); var brclass = RXObject.GetClass(typeof(BlockReference)); // iterate through the model space entity foreach (ObjectId id in modelSpace) { // check if the ObjectId refers to a BlockReference if (id.ObjectClass == brclass) { // do your stuff with the block ObjectId } } tr.Commit(); }
Thank you very much.
I used the first example.
it works faster.
Do you know where I can find descriptions of all codes?
@Anonymous wrote:
Do you know where I can find descriptions of all codes?
These are DXF 'group codes' and data.
0 stands for: "Entity type" ("INSERT" here).
410 stands for: "layout name" ("Model" here).
You'll find the DXF group codes reference here.
I use vb.NET
Dim intCode() As Int16
Dim varData() As Object
Dim blockRefObj As AcadBlockReference
intCode(0) = 0
intCode(1) = 410
varData(0) = "INSERT"
varData(1) = "Model"
Selection_Set.Select(CAD_Int_Com.AcSelect.acSelectionSetAll, Type.Missing, Type.Missing, intCode, varData)
For Each blockRefObj In Selection_Set
Debug.Print(blockRefObj.Name)
Next
but Selection_Set.count=0
Nothing is selected
Why?thanks.
Dim intCode(0 To 1) As Int16
Dim varData(0 To 1) As Object
Also does not work.
Can't find what you're looking for? Ask the community or share your knowledge.