Hi all
I have a problem understanding how undo marks are added to the undo stack.
In the code below a fan of lines are draw in a random location.
If you run MTest a few times, the AutoCAD Undo command will remove the fans one at a time.
If you run MMulti to draw 10 fans, the AutoCAD Undo command will remove all the fans in a single step.
I want to be able to remove the fans one at a time.
I thought that a StartTransaction / Commit pair would act as markers for the undo stack, but this isn't working.
Tested on AutoCAD 2010 VS 2008
<CommandMethod("MMult")> _
Sub testmult()
Dim i As Integer
For i = 1 To 10
Call testdraw()
Next
End Sub
<CommandMethod("MTest")> _
Sub testdraw()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim dl As DocumentLock = doc.LockDocument(DocumentLockMode.ProtectedAutoWrite, Nothing, Nothing, True)
Dim db As Database = doc.Database
Dim tm As DBTransMan = db.TransactionManager
Dim i As Integer, objid As ObjectId
Dim ta As Transaction = tm.StartTransaction()
Try
Dim bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
Dim rx As Double = Rnd() * 10
Dim ry As Double = Rnd() * 10
For i = 1 To 10
Dim startpt As New Point3d(rx, ry, 0)
Dim endpt As New Point3d(rx + 1, ry + i / 10, 0)
Dim pLine As New Line(startpt, endpt)
objid = btr.AppendEntity(pLine)
tm.AddNewlyCreatedDBObject(pLine, True)
Next i
ta.Commit()
Catch ex As Exception
MsgBox("Problem: " & ex.Message)
Finally
ta.Dispose()
End Try
End Sub
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
For i = 1 To 10
Autodesk.AutoCAD.Internal.utils.SetUndoMark(True)
Calltestdraw()
Autodesk.AutoCAD.Internal.Utils.SetUndoMark(False)
Next
If you have the COM type libraries referenced into your project, you could use AcadDocument.StartUndoMark, and AcadDocument.EndUndoMark, instead of using something from the Internal namespace, but I'd rather use something from Internal than add the COM references to my project just for that.
FYI, I'm not sure how long that has been there (the Internal.Utils.SetUndoMark(bool)), but it wasn't there the last time I looked. Thanks for making me look again!
Perfect! Works OK. Thanks.
Where would I look for documentation on this?
No entry in the ObjectARX for 2010 help file
No entry in the Object browser for Acmgd
Andrew
It comes up in my Object Browser (that is how I found it, by searching for UndoMark), however, there is no documentation from Autodesk on the Internal namespace. It is "use at your own risk" stuff.
It is possible that when switching to a newer version of AutoCAD, that function may not be there anymore, but most of the time, if something disappears from the Internal namespace, that probably means it was moved into a supported namespace, as opposed to being deleted.