TheSwamp
Code Red => .NET => Topic started by: Joel Roderick on March 30, 2006, 11:45:53 AM
-
I have search the object browser high and low and cannot find a way to set an undo mark via the .net api. Can anyone lead me down the right path?
My workaround for now is this:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute("(vla-startundomark (vla-get-ActiveDocument (vlax-get-acad-object)))", True, False, False)
Thanks for any help
-
Hi Joel, I haven't worked with undo markers before but this may be what you're looking for -
AcEditorReactor::undoSubcommandMark
Search for that in the SDK help, it <edit>may be</edit> part of the arx wrapper api.
A tip with searching the .net api, you may have to look through the arx api to find a function that does what you need, although the code may not be clear the explanations can help you decide on which function to use. If the function is part of a c++ class there will most likely be a matching wrapper, if not it will most likely be a global function and you can pick which wrapper it may be in by the first 4 letters.
eg. the aced***** would be wrapped by the Editor class, acdb***** the Database and so on.
These functions won't have the class name before them like this - AcDbEntity::funcname()
hth
-
Have a look in the help for this -
Database Undo and Transaction Management Facilities.
-
The scope of a transaction is essentially your undo start and end markers.
Note that these can be nested, however, if you were to abort the outermost transaction, all inner/nested transactions are aborted as well.
Cheers,
Glenn.
-
So, if you wanted to implement this, maybe you could break your functions into seperate (not nested) transactions which sets the marker at the start/end of each transaction (?).
I don't fully understand why you would use this, if you issue a command it performs the operations and returns. If you want to undo it this will work. Should the user be able to undo certain steps in the operation?? If so maybe they should be written in seperate commands??
-
Mick,
A classic example of why you would want to do this is the 'LINE' command.
It allows you to UNDO segments as you go.
Essentailly it's a while loop asking for point selection or keyword. If point, then a line segment is added to the dbase
and is commited, whilst if the 'u' keyword, the current transaction is aborted.
Cheers,
Glenn.
-
Ah, ok. So you could probably still do this in a while loop.
Will have to give it a go.
Thanks Glenn.
-
Thanks for the tips...
My issue is this:
I have a program that adds rows to a table and also fills rows with text. I have each of these within their own transaction. For some reason, when I undo, it is not seeing these transactions as seperate "tasks". For example, if I add 3 rows and insert text in another and then undo, it undoes everything...
Here is the code I have. These this behind buttons on a palette. To give it a try, you will need a table with 5 columns. Insert a few rows and then undo. Thanks again for the help.
'setup variable
Dim editor As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim pOptions As PromptEntityOptions = New PromptEntityOptions("Select a table: ")
Dim pResults As PromptEntityResult = editor.GetEntity(pOptions)
Dim tbl As Table
Dim trans As Transaction
'start the transaction
trans = HostApplicationServices.WorkingDatabase().TransactionManager.StartTransaction()
Try
'lock the document
editor.Document.LockDocument()
'get the object and open it for write
tbl = trans.GetObject(pResults.ObjectId, OpenMode.ForWrite)
Dim ht As TableHitTestInfo
ht = tbl.HitTest(pResults.PickedPoint, Vector3d.ZAxis)
'add the strings
tbl.SetTextString(ht.Row, 1, "test 1")
tbl.SetTextString(ht.Row, 2, "test 1")
tbl.SetTextString(ht.Row, 3, "test 1")
tbl.SetTextString(ht.Row, 4, "test 1")
'commit the changes
trans.Commit()
Catch
Finally
'dispose the transaction
trans.Dispose()
End Try
-
Dim doc As IAcadDocument = CType(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument, IAcadDocument);
doc.StartUndoMark();
..............
doc.EndUndoMark();
Also you nead add reference to AutoCAD 200X Type Library and AutoCAD/ObjectDBX Common 16.0 Type Library and also add line in module:
Imports Autodesk.AutoCAD.Interop