How to Execute a Modifier plugin in Expression priority
-
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!
-
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 -
@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)
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)
-
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:
Cheers,
IliaPython tag code:
import c4d def main() -> None: print('tag')
stemp.pyp code:
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) 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 )
-
@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