theSession.DeleteUndoMark (). Is it required/needed?

To all

A stupid question but one I have to ask. When recording journal to get keywords one sees a lot of statement such as

Dim markId2 As Session.UndoMarkId
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markId1, "Evaluate Elemental Function Response")

one explanation I have found in the doc is:
UndoMarkId = This is used to rollback to previous states of the model

So the (stupid) questions are:
1/ What do these statements exactly do in a journal?
2/ Do I need them?

Any inputs/explanation would be welcome

Thanks

Regards

JXB

Undo marks have two main uses:

  • allow the user to undo the results of the journal
  • allow the journal to roll back to an earlier state if an error occurs

If the journal code creates new objects or modifies existing ones, it is a good idea to create a visible undo mark before the changes are made. If, after the journal completes, the user decides that the changes were not desired, he/she can use the "undo" functionality in interactive NX to reverse the changes made by the journal. Without an undo mark, the user is stuck with the change and would have to modify the model by hand to reverse the changes made by the journal.

The Session object has a few "undo" methods that will allow you to roll back to a previous undo mark within your journal. This works well in conjunction with Try/Catch blocks; set an undo mark before attempting code that main fail, if an error occurs, you can easily roll back to the previous "good" state before the error occurred. Some pseudocode:

set undo mark

change NX settings as required for journal

Try
code that may fail
Catch ex as NXException
theSession.UndoToMark(theUndoMark)
message to user
End Try

In the example above, rather than reversing all the changes we made to the NX settings, we can simply undo to the appropriate mark that we have created.

Thanks for the input/clarification NXJournaling. Much appreciated. It looks like I do have a "Dim markId1 As Session.UndoMarkId" in the only macro making change(s) to an fem. I do not know where it come from (a copy-paste action from a journal I guess!)

Thanks
Regards