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

quick selection of all "AcDbBlockReference".

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
1536 Views, 7 Replies

quick selection of all "AcDbBlockReference".

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"?

 

 

 

 

7 REPLIES 7
Message 2 of 8
_gile
in reply to: Anonymous

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();
            }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 8
Anonymous
in reply to: _gile

Thank you very much.
I used the first example.
it works faster.

 

Do you know where I can find descriptions of all codes?

Przechwytywanie.PNG

Message 4 of 8
_gile
in reply to: Anonymous


@Anonymous wrote:

Do you know where I can find descriptions of all codes?

Przechwytywanie.PNG


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.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 8
dalian_mudong
in reply to: _gile

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.

Message 6 of 8
dalian_mudong
in reply to: Anonymous

Dim intCode(0 To 1) As Int16
Dim varData(0 To 1) As Object

Also does not work.

Message 7 of 8

Solved by myself

Message 8 of 8

Solved by myself

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report