Api Undo - Where is the line?

Api Undo - Where is the line?

Nico0307
Participant Participant
554 Views
2 Replies
Message 1 of 3

Api Undo - Where is the line?

Nico0307
Participant
Participant

Hi everyone,

 

so I've implemented this api command that uses mfnCamera and plugs to modify the camera's transform.

It's implemented as an mpxcommand and i do not use dgmod's doit in the doIt()

 

In fact I want the command to be non-undoable, however as we know:

"Any command that manipulates the state of the Dependency Graph and its nodes, including the DAG, should implement MPxCommand::undoIt() and MPxCommand::isUndoable(), ..."

Also:

"Only commands that query the scene or do not modify it in any way should be non-undoable. If you create a non-undoable command that modifies the scene, it will break Maya's undo capability."

(from Maya help about undo)

 

These are seemingly clear rules, but since Maya also allows to disregard camera undo from within the preferences I wonder if there's maybe a finer line than that.

I don't recall ever experiencing stability issues from changing a couple attributes on node's here and there but to be fair I wouldn't attempt this on something like mesh modifiers.

 

So where's the line? Can I implement my camera command without undo at all?

Does maya have a special undo for camera related actions that isn't exposed in the api?

 

Thank you for your input,

Nicolas

0 Likes
Accepted solutions (1)
555 Views
2 Replies
Replies (2)
Message 2 of 3

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

Yes, cameras have their own undo system that is separate from the main Maya undo stack. This is not exposed in the API and is managed by the various camera tools/commands.


screenshot_000363.png


So it is ok/expected that your custom camera command would not be undoable to better match the behaviour of existing camera commands in Maya.

To answer your other question changing attributes in a non-undoable way will not cause any issues as far as undo is concerned.

However, anything that changes the structure of the node graph (adding/removing nodes or connections etc.) could lead to crashes during undo unless the undo queue was flushed after running those commands.

Brent McPherson
Principle Engineer
Message 3 of 3

Nico0307
Participant
Participant

Thank you very much!

 

This really helps going forward and with my command. I will cautiously stick to what you said.

 

I have now implemented the command so that it will only be undoable/redoable if the user has checked "Undoable Movement" under View->Camera Settings. On top of that, it seems like "Undo View Change" picks up on most of the camera changes in the command for free as well, regardless of whether the command is undoable.

0 Likes