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 Problem For TagData Plugin

    Cinema 4D SDK
    python r23
    2
    4
    577
    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.
    • beatgramB
      beatgram
      last edited by Manuel

      Hey folks,

      I encountered Undo related issue again. It might be due to my lack of understanding for undo things but let me ask you a question.

      I wrote a test tag plugin with python which follows another object's position with a little offset.
      It simply works but when I undo, the object that has the tag doesn't react until I click somewhere (see below).

      Is it possible to solve this issue with python?
      I know undo things are prohibited in execute() of tagdata, so is there any workaround?

      Please help me if you know the solution.

      undo_issue_1.gif

      Here's quick code for this.

      testtag.pyp

      import os
      import c4d
      from c4d import plugins, bitmaps, utils
      
      
      PLUGIN_ID = *******
      
      
      class TestTagData(plugins.TagData):
          def Init(self, node):
              pd = c4d.PriorityData()
              if pd is None:
                  raise MemoryError("Failed to create a priority data.")
              pd.SetPriorityValue(lValueID = c4d.PRIORITYVALUE_MODE, data = c4d.CYCLE_INITIAL)
              node[c4d.EXPRESSION_PRIORITY] = pd
              return True
      
          def Execute(self, tag, doc, op, bt, priority, flags):
              bc = tag.GetDataInstance()
              obj = bc.GetLink(c4d.TTEST_TARGET_OBJECT)
              if obj is None:
                  return False
              mrx = obj.GetMg()
              mrx.off += c4d.Vector(100, 0, 0)
              op.SetMg(mrx)
              return c4d.EXECUTIONRESULT_OK
      
      
      if __name__ == "__main__":
          plugins.RegisterTagPlugin(id = PLUGIN_ID, str = "Test Tag", info = c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE, g = TestTagData, description = "ttest", icon = None)
      

      ttest.res

      CONTAINER Ttest
      {
          NAME Ttest;
          INCLUDE Texpression;
      
          GROUP ID_TAGPROPERTIES
          {
              LINK TTEST_TARGET_OBJECT
              {
                  ANIM ON;
                  ACCEPT { Obase; };
              }
      }
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        this is probably a bug here, i need to investigate a bit more.
        Instead of retrieving the object using the BaseContainer, use the bracket notation.

        You will receive the right object with the correct Matrix.

        obj = tag[c4d.TTEST_TARGET_OBJECT]
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        beatgramB 1 Reply Last reply Reply Quote 0
        • beatgramB
          beatgram @Manuel
          last edited by beatgram

          @m_magalhaes Thank you for your checking, Manuel.

          I didn't think it's a bug! And yep, your workaround with bracket notation works fine.
          So these bracket notation style is safer than using BaseContainer in any case?
          Anyway, let us know if you confirm this is a bug.

          ManuelM 1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel @beatgram
            last edited by

            hi,

            @beatgram said in Undo Problem For TagData Plugin:

            So these bracket notation style is safer than using BaseContainer in any case?

            this should be exactly the same.
            Sorry i didn't got time to warp my head around it.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

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