- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.