.NET

Reply
Active Member
Hans530
Posts: 8
Registered: ‎03-03-2012
Message 1 of 8 (310 Views)

Filter Dynblockreferences in selection

310 Views, 7 Replies
03-22-2012 09:49 AM

Hi

I have a problem with selecting all references to a specific dynamic block. When I use the filter below only block “D2” is selected, which is not a dynamic block, Block "Bulb120227” which is a dyn block is not

Dim values() As TypedValue = { _

                New TypedValue(0, "INSERT"), _ 

                New TypedValue(-4, "<OR"), _ 

                New TypedValue(2, "D2"), _ 

                New TypedValue(2, "Bulb120227"), _

                New TypedValue(-4, "OR>") _ 

               }

How should the filter be done to filter out the dyn block that I want several block should be filtered out in one selection.

If it is possible to achieve with just a filter at all?

With regards to you All

HansP

Valued Mentor
gasty1001
Posts: 450
Registered: ‎04-11-2010
Message 2 of 8 (300 Views)

Re: Filter Dynblockreferences in selection

03-22-2012 12:27 PM in reply to: Hans530

Hi,

 

If the block is dynamic, you need to check against the effectivename of the block:

 

Public Shared Function GetEffectiveName(ByVal blkref As BlockReference, ByVal acTrans As transaction) As String
        Dim btr As BlockTableRecord

        btr = acTrans.GetObject(blkref.DynamicBlockTableRecord, OpenMode.ForRead)
        Return btr.Name

End Function

 Gaston Nunez

 

Active Member
Hans530
Posts: 8
Registered: ‎03-03-2012
Message 3 of 8 (290 Views)

Re: Filter Dynblockreferences in selection

03-22-2012 02:30 PM in reply to: Hans530

Hi

I will try to explain what I am trying to accomplish
What I want is a command that selects all dynamic block references in a drawing
To do this my strategy is as follows
Stepping through the block collection finding all dynamic block definitions and their name
making the list on the format

            Dim values() AsTypedValue = { _

               NewTypedValue(0, "INSERT"), _

               NewTypedValue(-4, "<OR"), _

               NewTypedValue(2, "D2"), _

               NewTypedValue(2, "H-Balk101026"), _
                              |

                              |

                              |
              
NewTypedValue(2, "H-Balk101036"), _

               NewTypedValue(-4, "OR>") _

               }

Then making the filtered selection

 

            Dim sfilter As New SelectionFilter(values)
           
Dim res As PromptSelectionResult = ed.SelectAll(sfilter)

 

Doing like this all references to block ”D2”, which are not a dynamic are selected, but references to block "H-Balk101026" which are  dynamic are not selected.
I get the same result if the filterlist are “hardcoded” or if program are building it.

With the list below, all blockreferences are selected dynamic and static

 

             Dim values() AsTypedValue = { _

                  NewTypedValue(0, "INSERT"), _

                              }

How should the filter be sett upp, or the selection be done please HELP

HansP

 

Valued Mentor
jeff
Posts: 323
Registered: ‎05-12-2009
Message 4 of 8 (289 Views)

Re: Filter Dynblockreferences in selection

03-22-2012 02:32 PM in reply to: gasty1001

Look at BlockTableRecord.GetBlockReferenceIds

and

BlockTableRecord.GetAnonymousBlockIds

You can also find your answers @ TheSwamp
Valued Mentor
gasty1001
Posts: 450
Registered: ‎04-11-2010
Message 5 of 8 (284 Views)

Re: Filter Dynblockreferences in selection

03-22-2012 03:45 PM in reply to: Hans530

Hi,

 

I think you can't filter a priori by blockname, as the dynamic block goes anonimous if some of  their dynamic properties is activated, so you must filter for generic, check if is dynamic, and then get the effective name like this:

 

Public Function CDBLx() As 'Something
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim BlkList As New List(Of String)

        BlkList.Add("BLK1")
        BlkList.Add("BLK2")
        BlkList.Add("BLK3")

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Dim acTypValAr(0) As TypedValue

            acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)

            Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
            Dim acSSPrompt As PromptSelectionResult

            acSSPrompt = ed.SelectAll(acSelFtr)

            If acSSPrompt.Status = PromptStatus.OK Then
                Dim acSSet As SelectionSet = acSSPrompt.Value
                For Each acSSObj As SelectedObject In acSSet
                    Dim blk As BlockReference = acSSObj.ObjectId.GetObject(OpenMode.ForRead)
                    If blk.IsDynamicBlock Then
                        If BlkList.Contains(GetEffectiveName(blk, acTrans).ToUpper) Then
                            'Do Something here...
                        End If
                    End If
                Next
            End If
        End Using
        Return 'Something...
    End Function

Gaston Nunez 

 

 

Valued Mentor
jeff
Posts: 323
Registered: ‎05-12-2009
Message 6 of 8 (279 Views)

Re: Filter Dynblockreferences in selection

03-22-2012 05:55 PM in reply to: gasty1001

Was talking about using GetBlockReferenceIds() for BlockReferences that have not been modified by a dynamic properties and use GetAnonymousBlockIds to get the anonymous blocks created.

 

Quote from docs

BlockTableRecord.GetAnonymousBlockIds

Retrieves a collection populated with the ObjectIds of the anonymous blocks created from the dynamic block definition.

 

Also if you have collection of BlockReferences and want to to filter for if created from a Dynamic Block you could just get the Dynamic's BlockTableRecord ObjectId and remove the ones that its BlockReference.DynamicBlockTableRecord does not match

 

 

 

You can also find your answers @ TheSwamp
Active Member
Hans530
Posts: 8
Registered: ‎03-03-2012
Message 7 of 8 (240 Views)

Re: Filter Dynblockreferences in selection

03-28-2012 01:38 AM in reply to: jeff

Hi

 Thank you all for getting back to me.
It seems that the filter can’t handle anonymous, names type “*Uxx”
To get around this. Here is my solution to accomplice my needs

 

 

<CommandMethod("HMDR", CommandFlags.Session)> _
        Public Sub How_Many_dynamic_References()


            Dim dyn_blockOBJ() As String
            Dim n, nn As Integer
            nn = 0
            For n = 0 To ThisDrawing.Blocks.Count - 1
                Dim blockObj As AcadBlock


                If Not ThisDrawing.Blocks.Item(n).IsDynamicBlock Then
                    blockObj = ThisDrawing.Blocks.Item(n)
                    ReDim Preserve dyn_blockOBJ(nn)
                    dyn_blockOBJ(nn) = blockObj.Name

                    nn = nn + 1
                End If
            Next



            Dim values(2) As TypedValue
            values(0) = New TypedValue(DxfCode.Start, "INSERT")
            values(1) = New TypedValue(-4, "<NOT")
            values(2) = New TypedValue(-4, "<OR")
            n = 2
            

            For Each itn As String In dyn_blockOBJ
                n = n + 1
                ReDim Preserve values(n)
                values(n) = New TypedValue(DxfCode.BlockName, itn)

            Next

            n = n + 1
            ReDim Preserve values(n)
            values(n) = New TypedValue(-4, "OR>")

            n = n + 1
            ReDim Preserve values(n)
            values(n) = New TypedValue(-4, "NOT>")

            MsgBox(values.Count)
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim sfilter As New SelectionFilter(values)
            Dim res As PromptSelectionResult = ed.SelectAll(sfilter)





            
            If Not res.Status = PromptStatus.OK Then Return
            Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
            Dim idarray As ObjectId() = SS.GetObjectIds()

            If idarray.Count <> 1 Then Return




            'MsgBox("OK")
        End Sub

 

 

When I  use the code in a project started with Template provided by Autodesk  the lines

 

 

MsgBox(values.Count)
And
If idarray.Count <> 1 Then Return

 


Returns an error saying that Error    'Count' is not a member of 'System.Array'
If I use a project started as a Dll importing all references and namespaces I do not get this error All references and imports are identical in both Projects
Can anybody explain this

/HansP

*Expert Elite*
Alfred.NESWADBA
Posts: 8,895
Registered: ‎06-29-2007
Message 8 of 8 (238 Views)

Re: Filter Dynblockreferences in selection

03-28-2012 01:56 AM in reply to: Hans530

Hi,

 

>> Count' is not a member of 'System.Array

Try this instead:

 

if idarray.GetLength(0) ...

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community