Solved Undo for a TagData?

I have a TagData Python plugin. It uses a loop to iterate all the children of the object it's applied to and changes their parameters after the hierarchy changes. All that happens in Execute().
I tried to wrap it all with usual Start/Add/EndUndo(). But.. It doesn't work.
I simplified the code to check how it works. So after the trigger action it simply changes the main node name.

doc.StartUndo()
doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)

op.SetName("blah")

doc.EndUndo()
c4d.EventAdd()

It does not undo the name change back on user undo.
What am I doing wrong?

As said previously this is not possible in the execute method to add an undo event because this execute method is called during the execute.

But if I understood correctly you have an UserData attached then this UD drive children parameters. If that's the case you can react to this parameter change (coming from the GUI which is a Main Thread thing) and then apply the undo.
You can find an example in https://plugincafe.maxon.net/topic/12479/update-button/3

Cheers,
Maxime.

Hi,

you cannot add or invoke Undos in the execution of nodes (e.g.: TagData.Execute), because it runs in a threaded context. See Threading Information.

Cheers,
zipit

MAXON SDK Specialist
developers.maxon.net

You should only create undos for changes done by the user while interacting with the document:

No undos should be created in expressions or generators etc. Undos should be created when the user interacts with the scene.

See Undo System Manual.

I forgot about that totally...
But maybe is there a way to catch the undo and do something before the actual undo?
I tried to catch MSG_DESCRIPTION_INITUNDO through the Message() but it didn't work too, all I get is None

As said previously this is not possible in the execute method to add an undo event because this execute method is called during the execute.

But if I understood correctly you have an UserData attached then this UD drive children parameters. If that's the case you can react to this parameter change (coming from the GUI which is a Main Thread thing) and then apply the undo.
You can find an example in https://plugincafe.maxon.net/topic/12479/update-button/3

Cheers,
Maxime.