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
    • Register
    • Login

    How to Execute a Modifier plugin in Expression priority

    Cinema 4D SDK
    2024 python
    2
    7
    255
    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.
    • chuanzhenC
      chuanzhen
      last edited by

      Hi,
      I have created a object modifier plugin and I want it to work once in priority Expression 10, and then again in Generator 1. How can I make it work as expected?
      In the code, AddToExecution() and Execute() do not seem to work (the documentation states that switching priorities requires calling these two functions).

      import c4d
      from c4d import plugins, bitmaps
      
      
      PLUGIN_ID = 1000001
      
      class S_Temp(plugins.ObjectData):
      
      
          def Execute(self, op, doc, bt, priority, flags) -> int:
              print("Execute")
              return c4d.EXECUTIONRESULT_OK
      
          def AddToExecution(self, op, list) -> bool:
              print("AddToExecution")
              return True
      
      
          def Init(self, node, isCloneInit: bool) -> bool:
              self.InitAttr(node, c4d.BaseList2D, c4d.S_TEMP_POSEDTARGETS)
              self.InitAttr(node, c4d.BaseList2D, c4d.S_TEMP_POSEDSOURCEADD)
              self.InitAttr(node, c4d.PriorityData, c4d.S_TEMP_PRIORITY)
      
              if not isCloneInit:
                  pridata = c4d.PriorityData()
                  pridata.SetPriorityValue(c4d.PRIORITYVALUE_MODE, c4d.CYCLE_EXPRESSION)
                  pridata.SetPriorityValue(c4d.PRIORITYVALUE_PRIORITY, 10)
                  node[c4d.S_TEMP_PRIORITY] = pridata
              return True
      
          def ModifyObject(self, mod, doc, op, op_mg, mod_mg, lod, flags, thread):
              allp = [pos + c4d.Vector(0,100,0) for pos in op.GetAllPoints()]
              op.SetAllPoints(allp)
              op.Message(c4d.MSG_UPDATE)
      
              return True
      
      
      if __name__ == '__main__':
          plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="S_Temp", g=S_Temp, description="stemp", info=c4d.OBJECT_MODIFIER,
                                       icon=None)
      

      Here is the file of this plugin --> s_Temp.zip

      Thanks for any help!

      相信我,可以的!

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @chuanzhen
        last edited by

        Hi @chuanzhen,

        Sorry for the late answer and thanks for providing a great explanation of your question with the code snippet and a sample plugin, highly appreciated!

        I suspect, the missing bit in your case is the c4d.OBJECT_CALL_ADDEXECUTION flag that you need to add for your object plugin registration function call.

        However, this will allow you to structure the sequence of calling the Execute() function. You cannot queue the execution of the ModifyObject() function.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        chuanzhenC 1 Reply Last reply Reply Quote 0
        • chuanzhenC
          chuanzhen @i_mazlov
          last edited by

          @i_mazlov Thanks for reply!
          I added this flag and modified the content of AddToExecution(). Execute() was successfully called, but it did not run in the expected calculation order. In the image below, The Cube object has a Python tag with priority=expression 0 and objectplugin with priority=expression 10. My expected work order should be python tag (priority=expression 0) -> objectplugin (priority=expression 10), but why is the actual running result objectplugin (priority=expression 10) ->python tags (priority=expression 10)
          bd57c2f7-c340-4c85-a9f3-ed22600fbb19-image.png

          my code:

              def Execute(self, op, doc, bt, priority, flags) -> int:
          
                  print("Execute")
                  return c4d.EXECUTIONRESULT_OK
          
              def AddToExecution(self, op, list) -> bool:
                  print("AddToExecution")
                  mode = op[c4d.S_TEMP_PRIORITY].GetPriorityValue(c4d.PRIORITYVALUE_MODE)
                  list.Add(op, mode,c4d.EXECUTIONFLAGS_NONE)
          

          相信我,可以的!

          i_mazlovI 1 Reply Last reply Reply Quote 0
          • i_mazlovI
            i_mazlov @chuanzhen
            last edited by i_mazlov

            Hi @chuanzhen,

            With the code snippet below and Cinema 4D 2025.2.0 I cannot reproduce your issue. Namely the python tag with Expression-0 and the object modifier with Expression-10 work as expected:
            d6bc0ded-7a01-4ac0-8557-ac7b30b0600b-image.png
            c2f05105-1d54-4dbb-9b0d-885d0d7997b9-image.png

            Cheers,
            Ilia

            Python tag code:

            import c4d
            def main() -> None:
                print('tag')
            

            stemp.pyp code:
            Upd 14/04/25: fixed the list.Add() function

            import c4d
            PLUGIN_ID = 1051592
            class S_Temp(c4d.plugins.ObjectData):
                def Init(self, node, isCloneInit: bool) -> bool:
                    print('stemp-Init')
                    return True
                
                def AddToExecution(self, op, list) -> bool:
                    print("stemp-AddToExecution")
                    list.Add(op, c4d.EXECUTIONPRIORITY_EXPRESSION + 10, c4d.EXECUTIONFLAGS_NONE)
                    return True
                
                def Execute(self, op, doc, bt, priority, flags) -> int:
                    print(f"stemp-Execute: {priority}")
                    return c4d.EXECUTIONRESULT_OK
            
                def ModifyObject(self, mod, doc, op, op_mg, mod_mg, lod, flags, thread):
                    print(f"stemp-ModifyObject: {op.GetName()}")
                    allp = [pos + c4d.Vector(0, 100, 0) for pos in op.GetAllPoints()]
                    op.SetAllPoints(allp)
                    op.Message(c4d.MSG_UPDATE)
                    return True
            
            if __name__ == '__main__':
                c4d.plugins.RegisterObjectPlugin(
                    id=PLUGIN_ID,
                    str="S_Temp",
                    g=S_Temp,
                    description="stemp",
                    info=c4d.OBJECT_MODIFIER | c4d.OBJECT_CALL_ADDEXECUTION,
                    icon=None
                )
            

            MAXON SDK Specialist
            developers.maxon.net

            chuanzhenC 1 Reply Last reply Reply Quote 0
            • chuanzhenC
              chuanzhen @i_mazlov
              last edited by

              @i_mazlov Thanks,in my code I found an error and directly used the value obtained from PRIORITYVALUEMYODE in the priority GUI to set the list The priority parameter in Add() is a low-level error.
              But there is still a problem. When I used your code and adjusted the priority of **Python tag*to expression 1, the calculation order did not execute as expected. Where exactly is the problem?
              My version is also 2025.2.0
              aa3b604f-b0ba-49cc-8b40-6276b19dca35-image.png
              c438db28-6569-45f8-b1d8-82049db07a2b-image.png

              相信我,可以的!

              i_mazlovI 1 Reply Last reply Reply Quote 0
              • i_mazlovI
                i_mazlov @chuanzhen
                last edited by

                Hi @chuanzhen,

                The issue you're seeing is because I misused the list.Add() function in my previous example, sorry for that. Namely, the arguments are different, from how I used them. If you like to have priority "Expression 10", you'd need to use the following line:

                list.Add(op, c4d.EXECUTIONPRIORITY_EXPRESSION + 10, c4d.EXECUTIONFLAGS_NONE)
                

                I've updated the script in my previous posting with the proper usage of the list.Add() function.

                Please refer to an adjacent thread regarding execution flags: Priority: PriorityData and PriorityList

                Cheers,
                Ilia

                MAXON SDK Specialist
                developers.maxon.net

                chuanzhenC 1 Reply Last reply Reply Quote 0
                • chuanzhenC
                  chuanzhen @i_mazlov
                  last edited by

                  @i_mazlov Thanks,it works!

                  相信我,可以的!

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