I need to get control over the undo process in AutoCAD. (vs 2008 for now). I have many objects floating around the screen, and when the user undoes a move, I need to refresh the object's data on the palette (custom palette).
I have been made aware that undo fires off ObjectModified events, so I began stepping into that. What I found is that I am getting back a bunch of Xrecords. But what are they for and what do they contain? Digging a little deeper, I found that they contain abunch of integer32 objects. These values are not recognized as handles or objectIDs. So now I am stumped.
I know that the xrecords coorespond to the objects I moved, because the pattern repetition = the number of objects I have. All I need is the way to find the handle of the blockref's being 'undone', then I'm set. Any clue out there?
Here is my event handling code/test routine:
Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
If IgnoreEvents Then Exit Sub
Dim ibe As Boolean = Me.IgnoreEvents
Try
IgnoreEvents = True
If Not e.DBObject.IsWriteEnabled Then
WorkEvent(e.DBObject, "Modified") 'this is where an actual handle is found from the dboject.
If e.DBObject.GetType.Equals(GetType(DBDictionary)) Then
Dim trans As Transaction = db.TransactionManager.StartTransaction
Dim ent As Object = trans.GetObject(e.DBObject.ObjectId, OpenMode.ForRead)
If TypeOf ent Is DBDictionary Then
Dim dbd As DBDictionary = ent
Dim enu As DbDictionaryEnumerator = dbd.GetEnumerator
While enu.MoveNext
Dim dbe As DBDictionaryEntry = enu.Current
Dim xrec As Xrecord = dbe.Value.GetObject(OpenMode.ForRead)
'Debug.Print(xrec.Data.AsArray(0).Value.GetType.ToString)
Dim int As Int32 = xrec.Data.AsArray(0).Value
'This is where I attempted to convert the number to a handle or objectID. The drawing database didn't recognize either.
'Dim han As Handle = New Handle(int)
'Dim oid As ObjectId = db.GetObjectId(False, han, 1)
'Dim obj As Object = trans.GetObject(oid, OpenMode.ForRead)
'Debug.Print(obj.GetType.ToString)
End While
End If
End If
End If
Catch ex As System.Exception
Dim aex As New System.Exception("Error at Modify Object AutoCAD Event: ", ex)
Me.HandleError(aex)
Finally
IgnoreEvents = ibe
End Try
End Sub
and for the record... you can run a 'transaction' inside of an event. Just don't try to open something for write.
Thanks,
jvj