Write a python code into a Python Effector
-
Hello,
I want to insert a code (not written yet) into a python effector I created through a Python script. I figured out how to open the Editor but not how to change the code inside.Can you help please ?
(running on R21)import c4d from c4d import gui from c4d.modules import mograph as mo def PythonEffector(): PythonEffector = c4d.BaseList2D(1025800) #PythonEffector(c4d.OEPYTHON_OPENEDITOR) >> CHANGE THAT CODE WITH SOMETHING ELSE doc.InsertObject(PythonEffector) c4d.EventAdd() # Main function def main(): PythonEffector() # Execute main() if __name__=='__main__': main()
-
In fact in this Effector I would like to create an id selection for the operator it will be linked to.
So I can add this code into the effector
-
Simply address the code field as a string:
PythonEffector[c4d.OEPYTHON_STRING] = "# This is some Python code I'd like to see"
-
@Hugo-BATTISTELLA said in Write a python code into a Python Effector:
In fact in this Effector I would like to create an id selection for the operator it will be linked to.
So I can add this code into the effector
Not sure whether I understand what you want... but changing the cloner the effector is used in from within the effector seems very unadviseable to me, as an Effector can be used in more than one cloner.
If you have a specific Cloner in mind, you can access its list of effectors through
Cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST]But I guess you mean something else by "operator"...?
-
@Cairyn thank you for answer
I can now add a line of code but how Can I add multiples lignes of code in the effector. I got some difficulties to manage this.
What I would like is to make a selection by ID of the cloner through the Python Effector.
-
@Hugo-BATTISTELLA said in Write a python code into a Python Effector:
@Cairyn thank you for answer
I can now add a line of code but how Can I add multiples lignes of code in the effector. I got some difficulties to manage this.
Basic Python multiline strings?
PythonEffector[c4d.OEPYTHON_STRING] = ( "# This is some Python code I'd like to see\n" "# A second line\n" "import c4d\n" "main()" )
What I would like is to make a selection by ID of the cloner through the Python Effector.
As far as I can see, there is no way to retrieve the cloner the effector is currently working on from the MoData that you can call up. Have you studied all the examples already? (Linked in the MoData docs)
See also push_apart_effector.c4d, py_effector_random.c4d and py_effector_shape.c4d scene examples.
-
The multilines code works well.
Do you mean that there is no possibility to select clones ID to affect them with the Python Effector ?
-
@Hugo-BATTISTELLA said in Write a python code into a Python Effector:
The multilines code works well.
Do you mean that there is no possibility to select clones ID to affect them with the Python Effector ?
uh, you said "ID of the cloner" originally. Not clones.
If you want to identify a single clone, you can use the MoData function
index = md.GetCurrentIndex()
But that's part of the default code in the Python effector already.
(And the reference for the current cloner can be read from the predefined variablegen
.) -
Hi @Hugo-BATTISTELLA and @Cairyn,
thank you for reaching out to us. And thank you @Cairyn for stepping in. We cannot add anything to what @Cairyn already said. We would like however to bring up the fact that topics should be single subject as defined in the Forum Guidelines, as otherwise content will be hard to find for other users. It is fine in this case, but in the future, please open multiple topics for questions that are not direct follow-up questions, but questions with a new scope.
Thank you for your understanding,
Ferdinand -
@Cairyn Thank you for your help ! That's it. I confused it all with the wrong word. Sory... Your answers help me very nicely
@ferdinand I apologize about going out of the guidelines. I understand this and will create new topic for that point