SelectionFilter SelectAll with specific XData

SelectionFilter SelectAll with specific XData

wbdehaan
Enthusiast Enthusiast
1,837 Views
2 Replies
Message 1 of 3

SelectionFilter SelectAll with specific XData

wbdehaan
Enthusiast
Enthusiast

Hi,

 

Is it possible to select all objects (lines, polyline, blockreferences, circle etc) with specific Xdata added to the object? when I use the selectionfilter, it only selects polylines with Xdata.

In every drawn element I added specific Xdata. 

 

Dim doc = Application.DocumentManager.MdiActiveDocument
        Dim ed = doc.Editor

        '---Select objects with specific Xdata
        Dim ID As TypedValue = New TypedValue(1000, XdataString)
        Dim sf As SelectionFilter = New SelectionFilter(New TypedValue() {ID})
        Dim res = ed.SelectAll(sf)
        If res IsNot Nothing Then
            Dim objIds() As ObjectId = res.Value.GetObjectIds()
end if

Maybe it is because I added Xdata the wrong way?

 

Public Sub SetXData(ByVal ObjIDColl As ObjectIdCollection, ByVal tekst As String, ByVal Engineer as string)
       If ObjIDColl Is Nothing Then Exit Sub
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim docLock As DocumentLock = doc.LockDocument
        Dim ed As Editor = doc.Editor


        Dim AppName As String
        AppName = Algemeen.ProgName
        If AppName = "" Then AppName = "ThisMacro"
        '---
        Using MyTrans As Transaction = doc.TransactionManager.StartTransaction()
            AddRegAppTableRecord(AppName)
            For Each item In ObjIDColl
                Dim obj As Object = MyTrans.GetObject(item, OpenMode.ForWrite)

                '---remove previous Xdata
                If obj.XData IsNot Nothing Then
                    For Each tv As TypedValue In obj.XData
                        If tv.TypeCode = 1001 Then
                            obj.UpgradeOpen()
                            obj.XData = New ResultBuffer(New TypedValue(1001, tv.Value))
                            obj.DowngradeOpen()
                        End If
                    Next
                End If

                '---set new Xdata
                Dim rb As New ResultBuffer(New TypedValue(1001, AppName), New TypedValue(1000, tekst), New TypedValue(1000, Now), New TypedValue(1000, Engineer))

                '---Bind Xdata
                obj.XData = rb
                rb.Dispose()
            Next
            MyTrans.Commit()
        End Using
        docLock.Dispose()
    End Sub

kind regards,

 

Wouter

 

0 Likes
Accepted solutions (1)
1,838 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

With a selection filter, you can only filter on the registered application.

To filter on a specific xdata value, you have to open each selected object and check for its xdata values.

See this topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

wbdehaan
Enthusiast
Enthusiast

Thanks a lot! I will edit the Xdata, and move the specific ID to the appname, then it is possible to search on this appname.

0 Likes