Selection Filter Error -5001

Selection Filter Error -5001

SRSDS
Advisor Advisor
1,620 Views
8 Replies
Message 1 of 9

Selection Filter Error -5001

SRSDS
Advisor
Advisor

I have a problem with the selection filter returning an error (-5001).

I've narrowed it down..the problem only starts to occur after I've added Xdata to an entity. 

The selection filter works before that section of code.

Another odd thing is that the filter works if I use StartTransaction instead of StartOpenCloseTransaction.

But because it's an event I've been advised that I should be using StartOpenCloseTransaction.

 

 

 

 

0 Likes
Accepted solutions (1)
1,621 Views
8 Replies
Replies (8)
Message 2 of 9

SRSDS
Advisor
Advisor

This is a summary of the code with the problem

    Private Sub callback_CommandEnded(ByVal sender As Object, ByVal e As CommandEventArgs)
        If e.GlobalCommandName = "GRIP_STRETCH" Then
            Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()
                Using trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartOpenCloseTransaction : trcnt = trcnt + 1
                    Dim ent As Entity = TryCast(trans.GetObject(ObjID, OpenMode.ForRead), Entity)
                    'Filter Works fine here
                    'Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
                    'Dim values As TypedValue() = New TypedValue() {New TypedValue(CType(DxfCode.ExtendedDataRegAppName, Short), "BarLabel-2")}
                    'Dim filter As SelectionFilter = New SelectionFilter(values)
                    'psr = ed.SelectAll(filter)
                    'If psr.Status = PromptStatus.OK Then
                    'End If
                    WriteXdata(SomeOtherObjID, trans)
                    'Same Filter Doesn't
                    trans.Commit()
                End Using
            End Using
        End If
    End sub

Do I need to commit a StartOpenCloseTransaction after writing Xdata before trying to filter xdata?

Strange that the same problem doesn't occur with StartTransaction.

 

0 Likes
Message 3 of 9

ActivistInvestor
Mentor
Mentor

I can't tell you why you're seeing the problem you cite, but I'm not sure I follow the logic of your code. You are selecting all objects with Xdata for a certain application name from within a command-ended notification for the GRIP_STRETCH command.  If you're trying to act on the object(s) that were actually modified by the GRIP_STRETCH command, how are you identifying which of those were modified?

 


@SRSDSwrote:

This is a summary of the code with the problem

    Private Sub callback_CommandEnded(ByVal sender As Object, ByVal e As CommandEventArgs)
        If e.GlobalCommandName = "GRIP_STRETCH" Then
            Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()
                Using trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartOpenCloseTransaction : trcnt = trcnt + 1
                    Dim ent As Entity = TryCast(trans.GetObject(ObjID, OpenMode.ForRead), Entity)
                    'Filter Works fine here
                    'Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
                    'Dim values As TypedValue() = New TypedValue() {New TypedValue(CType(DxfCode.ExtendedDataRegAppName, Short), "BarLabel-2")}
                    'Dim filter As SelectionFilter = New SelectionFilter(values)
                    'psr = ed.SelectAll(filter)
                    'If psr.Status = PromptStatus.OK Then
                    'End If
                    WriteXdata(SomeOtherObjID, trans)
                    'Same Filter Doesn't
                    trans.Commit()
                End Using
            End Using
        End If
    End sub

Do I need to commit a StartOpenCloseTransaction after writing Xdata before trying to filter xdata?

Strange that the same problem doesn't occur with StartTransaction.

 


 

 

0 Likes
Message 4 of 9

SRSDS
Advisor
Advisor

I am acting on the object that was modified.

    Public Shared Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
        If GripStretchEvent = True And e.DBObject.XData IsNot Nothing Then
            Dim myXdata As Array = e.DBObject.XData.AsArray
            Dim arrSplit() As String = myXdata.GetValue(0).value.Split("-")
            If arrSplit(0) = "ABC"  Then
                ObjID = e.DBObject.ObjectId
            End If
        End If
        'NOTE TO SELF: USE THIS EVENT ONLY TO COLLECT OBJID
    End Sub

 

0 Likes
Message 5 of 9

ActivistInvestor
Mentor
Mentor

I still do not see what your purpose of using SelectAll() from a CommandEnded event handler is.

 


@SRSDSwrote:

I am acting on the object that was modified.

    Public Shared Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
        If GripStretchEvent = True And e.DBObject.XData IsNot Nothing Then
            Dim myXdata As Array = e.DBObject.XData.AsArray
            Dim arrSplit() As String = myXdata.GetValue(0).value.Split("-")
            If arrSplit(0) = "ABC"  Then
                ObjID = e.DBObject.ObjectId
            End If
        End If
        'NOTE TO SELF: USE THIS EVENT ONLY TO COLLECT OBJID
    End Sub

 


 

0 Likes
Message 6 of 9

SRSDS
Advisor
Advisor

Once the grip is stretched it filters out other entites with specific Appname Xdata and modifies them (and their XData) with any updated information. Probably got some terminology wrong in writing this.

 

 

 

 

 

 

0 Likes
Message 7 of 9

ActivistInvestor
Mentor
Mentor
Accepted solution

My guess on why you're having this problem is because you can't use SelectAll() or any other SelectXxxx() method in some, if not all event handlers, because those methods modify the previous selection set. Technically, You should never do anything that changes the previous selection set from what the user expects it to be. 

 

You can scan the database for the objects manually, rather than use SelectAll(), or you can store references to the objects you're trying to find in an extension dictionary attached to the object that's being modified, but that also requires you to deal with cloning.

0 Likes
Message 8 of 9

SRSDS
Advisor
Advisor

Does sounds like that’s the problem.

Hopefully it’s not that bad but it’ll take a while to fix.

 

I currently have objects grouped together using a ReferenceID in their entity XData

 

TypedValue(DxfCode.ExtendedDataRegAppName, "MyApp-" & ReferenceID)

 Each ReferenceID has a NOD entry which includes associated data.

 

Could I include a string list of object Handles to that entry buffer?

Adding and removing them if entities are added, cloned or deleted.

 

At least then I could still quickly identify the set ReferenceID and any associated objects.

0 Likes
Message 9 of 9

ActivistInvestor
Mentor
Mentor

@SRSDSwrote:

Does sounds like that’s the problem.

Hopefully it’s not that bad but it’ll take a while to fix.

 

I currently have objects grouped together using a ReferenceID in their entity XData

 

TypedValue(DxfCode.ExtendedDataRegAppName, "MyApp-" & ReferenceID)

 Each ReferenceID has a NOD entry which includes associated data.

 

Could I include a string list of object Handles to that entry buffer?

Adding and removing them if entities are added, cloned or deleted.

 

At least then I could still quickly identify the set ReferenceID and any associated objects.


Storing a reference to one object within another object can't be done reliably using handles in xdata. Inserting, WBlock'ing, and copying objects will break the references.

 

You have to use an XRecord in an extension dictionary, and store the ObjectIds of the referenced objects using the appropriate dxf codes (330-369). You also have to set the Xrecord's XlateReferences property to true.

 

 

0 Likes