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

Undo Understanding

3 REPLIES 3
Reply
Message 1 of 4
foruma000256
279 Views, 3 Replies

Undo Understanding

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
3 REPLIES 3
Message 2 of 4
foruma000256
in reply to: foruma000256

I solved this on my own, Autodesk tells me that they do not have a .net wrapper for undo, so I had to create something.

The event watcher helped out with this one...

handle these events:
db.ObjectModified
doc.CommandWillStart
doc.CommandEnded
ed.EnteringQuiescentState

Then:
command will start listen for the "U" command and set undo flag, allow object modifed to see all objects in any state.

object modified check flag, and collect dbobjects in array defined in class not routine handler

command ended will just reset your event handler flags

entering quiescent will see if your undo flag is active then run your undo process on your stored array of dbojbects which will clear your array when done.

my problem was the line "e.DBObject.IsWriteEnabled" That took all the objects i was listening for out of the loop. So I had to make sure that the undon objects were handled AFTER undo was finished processing.

Thats it folks...

jvj
Message 3 of 4
Anonymous
in reply to: foruma000256

wrote...

>> I solved this on my own..........Thats it folks...

Congradulations.

Now try right-clicking on the Properties Palette, and choosing "Undo" from the context menu....

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com
Message 4 of 4
foruma000256
in reply to: foruma000256

I'll pick that bone, after i get done redesigning my interface to be MUCH smaller like a real palette...

Thanks Master Tanzillo,

jvj

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost