Author Topic: Set an undo mark - VB.net  (Read 5280 times)

0 Members and 1 Guest are viewing this topic.

Joel Roderick

  • Guest
Set an undo mark - VB.net
« 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

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: Set an undo mark - VB.net
« Reply #1 on: March 30, 2006, 04:09:25 PM »
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
« Last Edit: March 30, 2006, 04:21:29 PM by MickD »
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: Set an undo mark - VB.net
« Reply #2 on: March 30, 2006, 04:49:56 PM »
Have a look in the help for this -

Database Undo and Transaction Management Facilities.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Set an undo mark - VB.net
« Reply #3 on: March 30, 2006, 06:19:50 PM »
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.
Me

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: Set an undo mark - VB.net
« Reply #4 on: March 30, 2006, 06:44:30 PM »
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??
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Set an undo mark - VB.net
« Reply #5 on: March 30, 2006, 11:56:10 PM »
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.
Me

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: Set an undo mark - VB.net
« Reply #6 on: March 31, 2006, 03:55:23 AM »
Ah, ok. So you could probably still do this in a while loop.
Will have to give it a go.
Thanks Glenn.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Joel Roderick

  • Guest
Re: Set an undo mark - VB.net
« Reply #7 on: March 31, 2006, 11:45:17 AM »
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.

Code: [Select]
'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

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: Set an undo mark - VB.net
« Reply #8 on: March 31, 2006, 01:10:39 PM »
Code: [Select]
       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:
Code: [Select]
Imports Autodesk.AutoCAD.Interop
« Last Edit: March 31, 2006, 01:32:54 PM by Rivilis »