Detecting undos

On 01/04/2016 at 21:35, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R13-R17 
Platform:    Mac  ;  Mac OSX  ; 
Language(s) :     C++  ;


I have a TagData plugin that uses SetDParameter() to update some data based on it.
But when I undo, it is not called, and the data remains outdated.
How can I detect a parameter was changed by undo?



On 02/04/2016 at 08:41, xxxxxxxx wrote:

Are you doing this around the changes:

doc->AddUndo(UNDOTYPE_CHANGE, someObj);
// do changes here

Edit by Andreas: Added the obj to the AddUndo call, so I can refer to it in my own post.

On 03/04/2016 at 16:03, xxxxxxxx wrote:


Because I have no idea how undo works.
I really  miss a developer's guide, this is the kind of basic info that I shouldn't be asking around.
Cinema 4D SDK is powerful and amazing, but each feature I need to explore is a painful  process of searching the example project, guessing from API methods and include files.
The best that can happen is to be lucky and find some working sample on the forums.
Learning the SDK by search, guessing, trial and error is very time consuming, a guide would help a lot.
Sorry about the rant...

On 04/04/2016 at 09:25, xxxxxxxx wrote:


first I'd like to say, we are aware of the lack of guidance in the SDK documentation. Sorry, for the inconvenience. We are working on it.

Then I'd like to add some details here:
Robert already demonstrated the creation of an "undo" (I mean, a point something can be undone to) as it is most commonly done in CommandData plugins.
In the background C4D makes a copy of the object passed in AddUndo() (very simplified and only really true for UNDOTYPE_CHANGE). And when the user calls Undo, then this copy will be copied back into the original object.
This already explains, that you don't see any SetDParameter() calls in this process. And it should make clear, that only one AddUndo() is needed for multiple parameter changes on the same object.
For a NodeData derived plugin, you don't have to worry about this, as long as you store all your data in the BaseContainer of the node. In case you have not, you will need to provide a proper CopyTo() implementation (basically copying everything that's not stored in the BaseContainer), so the undo mechanism can work properly.
The surrounding StartUndo()/EndUndo() calls provide the means to group several changes into one single undo step for user convenience.

Just for completeness (and probably of little use in your case), there's also MSG_DOCUMENTINFO_TYPE_UNDO (subtype of MSG_DOCUMENTINFO), which can be used to detect, if the user calls undo.

On 19/04/2016 at 07:16, xxxxxxxx wrote:

Thanks Andreas.
I still did not got the time to try it out, but I will soon.