Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Undo for a TagData?

    Cinema 4D SDK
    4
    5
    804
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • intenditoreI
      intenditore
      last edited by intenditore

      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?

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        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

        1 Reply Last reply Reply Quote 2
        • P
          PluginStudent
          last edited by

          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.

          1 Reply Last reply Reply Quote 1
          • intenditoreI
            intenditore
            last edited by intenditore

            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

            1 Reply Last reply Reply Quote 0
            • M
              m_adam
              last edited by

              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://developers.maxon.net/forum/topic/12479/update-button/3

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 1
              • First post
                Last post