That works find ! Thank you so much
Posts made by Hugo BATTISTELLA
-
RE: Insert User Data Track in Python
Hello @Cairyn,
thank you a lot for this answer. I try this quikly but now I have a better understanding of the Desclevels concept ! -
RE: Insert User Data Track in Python
This is what the code looks like now :
import c4d from c4d import gui #Création d'une piste pour chaque donnée utilisateur def AddAnimationTrack(op): LED = c4d.CTrack(c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER), c4d.DescLevel(c4d.ID_USERDATA,3,c4d.DTYPE_LONG))) op.InsertTrackSorted(LED) return True # Main function def main(): AddAnimationTrack(op) # Execute main() if __name__=='__main__': main()
-
RE: Insert User Data Track in Python
@cairyn said in Insert User Data Track in Python:
c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER),
c4d.DescLevel(userdata_entry,c4d.DTYPE_LONG))Hello ! Thank you for replying !
I've put your code but get a error :
"Traceback (most recent call last):
File "scriptmanager", line 19, in <module>
File "scriptmanager", line 15, in main
File "scriptmanager", line 9, in AddAnimationTrack
NameError: global name 'userdata_entry' is not defined"Maybe I didn't get what I should do with "userdata_entry"
-
Insert User Data Track in Python
Hello,
I would like to add track (timeline) for each user data I have set on a object .
Here is the code I tried, but I don't know why it's not workingHere is the code I wrote :
import c4d from c4d import gui #Création d'une piste pour chaque donnée utilisateur def AddAnimationTrack(op): LED = c4d.CTrack(op,c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA,1,c4d.DTYPE_GROUP),c4d.DescLevel(c4d.ID_USERDATA,2,c4d.DTYPE_GROUP),c4d.DescLevel(c4d.ID_USERDATA,3,c4d.DTYPE_REAL))) op.InsertTrackSorted(LED) return True # Main function def main(): AddAnimationTrack(op) # Execute main() if __name__=='__main__': main()
I work on R21.
You can see the scene here : ADD_TRACK - 1.c4dThank you for helping
-
RE: Write a python code into a Python Effector
@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
-
RE: 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 ?
-
RE: 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.
What I would like is to make a selection by ID of the cloner through the Python Effector.
-
RE: 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
-
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()
-
RE: LINK EFFECTORS TO CLONERS
Thank you @bentraje and @ferdinand !
You make the deal of the EffectorList function much clearer ! It works well now
-
LINK EFFECTORS TO CLONERS
Hello,
I'm very new on python and I would like to know how to link the "pyhton effector" I create in this exemple to the cloner. I tried to use the InsertObject function but it seems that it's not working. TEST_CLONERS_1.c4dI run on R21
Can you help ?
import c4d from c4d import gui from c4d.modules import mograph as mo def cloner_creation(): Cloner = c4d.BaseList2D(1018544) Cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 3 Spheres = c4d.BaseList2D(5160) doc.InsertObject(Cloner) doc.InsertObject(Spheres) Spheres.InsertUnder(Cloner) def effectorsCreation(): Effector = c4d.BaseList2D(1025800) EffectorList = c4d.InExcludeData() # Initialize an InExclude data Cloner.InsertObject(EffectorList) # Add effector to effectors list doc.InsertObject(Effector) # Main function def main(): cloner_creation() effectorsCreation() c4d.EventAdd() # Execute main() if __name__=='__main__': main()
-
RE: PYTHON - FIND ANY ID PORT
@zipit Hello back !
I tried to use the code your wrote and actualy, linking ports is working but creating ports by iterating into them and pick them by order's number doesn't seems to work.I had that kind of thing in the code I've sent (line 39, 40). But it doesn't work. I should have the first output of the "Mograph data" node (called "Données").
Can you explain my mistake ?
About your code I still can't create ports on nodes... I tried to create all out and in ports of the nodes but nothing appened. I've commented your lines where you link the ports to focus on ports creation... Can you help me with this please ?
import c4d def main(): # Create a null object and add an Xpresso tag to it. null = c4d.BaseList2D(c4d.Onull) null[c4d.ID_BASELIST_NAME] = "ESSAIM - DROTEK-NL" xpresso_tag = c4d.BaseList2D(c4d.Texpresso) null.InsertTag(xpresso_tag) # Crée la texture de référence Led c4d.CallCommand(202586) Ref_Led = doc.GetFirstMaterial() Ref_Led[c4d.MATERIAL_USE_COLOR] = False Ref_Led[c4d.MATERIAL_USE_REFLECTION] = False Ref_Led[c4d.MATERIAL_USE_LUMINANCE] = True Ref_Led[c4d.ID_BASELIST_NAME] = "REF_DROTEK-NL_LED" # Get the node master and the root noode of that graphview. master = xpresso_tag.GetNodeMaster() root = master.GetRoot() # Crée de nouveaux nodes dans l'éditeur python et ouvre les ports nécessaires Hierarchie_node = master.CreateNode(root, c4d.ID_OPERATOR_HIERARCHY, x=0, y=10) Hierarchie_node[c4d.GV_HIERARCHY_START_ID] = "DL" Hierarchie_node[c4d.GV_HIERARCHY_ITERATION_ID] = "P" Indice_objets = master.CreateNode(master.GetRoot(),400001152,None,150,10) ListeDeLiens_node = master.CreateNode(root, c4d.ID_OPERATOR_LINK, x=300, y=10) Obj_Essaim = master.CreateNode(root, c4d.ID_OPERATOR_OBJECT, x=600, y=10) Obj_Essaim.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN, flag = c4d.GV_PORT_FLAG_IS_VISIBLE) Obj_cloner = master.CreateNode(root, c4d.ID_OPERATOR_OBJECT, x=100, y=100) Obj_cloner.AddPort(c4d.GV_PORT_OUTPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_OUT, flag = c4d.GV_PORT_FLAG_IS_VISIBLE) mo_donnee = master.CreateNode(master.GetRoot(),1019010,None,250,100) # Get all in ports of the math node and select the first one. mo_donnee_out = mo_donnee.GetOutPorts() mo_donnee_out = mo_donnee_out[0] if mo_donnee_out else None Obj_Ref_Led = master.CreateNode(root, c4d.ID_OPERATOR_OBJECT, x=600, y=100) Obj_Ref_Led.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN, flag = c4d.GV_PORT_FLAG_IS_VISIBLE) # Start of code added by Ferdinand --------------------------------------- # Ports have two ways to be indexed: By an index (0, 1, 2, ...) # which just enumerates all ports and is dependent on the order in which # they have been created. But also by a construct with is similar to # DescIDs - (main id, sub id, user id). # # The identifier you have been using for creating the ports, e.g., # c4d.GV_OBJECT_OPERATOR_OBJECT_OUT, is stored in the main id. There can # technically be more than one port with a given main ID on a node, but # we will ignore this for now. In Python we have to iterate over all ports # to get a port by its main id. # Get the output port of the node containing it. I created an alias for # your name so that things are a bit more readable. outputNode, outputPort = Obj_cloner, None # Get over all ports until we find one with the main id in question. for port in outputNode.GetOutPorts(): outputPort = port break # The same for the input port of the other node. outputNode, outputPort = Obj_Ref_Led, None for port in outputNode.GetOutPorts(): outputPort = port break #Try to connect both ports. # if not (outputPort and inputPort and outputPort.Connect(inputPort)): # msg = "Could not find ports or could not connect ports." # raise RuntimeError(msg) # End of code added by Ferdinand ---------------------------------------- # Add our object to the scene graph and let Cinema update. doc.InsertObject(null) c4d.EventAdd() #liaison des bons objets aux nodes créés # Définition des objets cloner = doc.SearchObject("DROTEK-NL") # Récupère l'objet selon son nom. Rerefence_LED = doc.SearchMaterial("REF_DROTEK-NL_LED") # Récupère le matériaux selon son nom. Obj_cloner[c4d.GV_OBJECT_OBJECT_ID] = cloner # Lie le cloner "DROTEK-NL au Node "cloner" crée précédement. Obj_Ref_Led[c4d.GV_OBJECT_OBJECT_ID] = Rerefence_LED if __name__=='__main__': main()
-
RE: PYTHON - FIND ANY ID PORT
@zipit Thank you !
Your answer is quite clear !
I try to use this as soon as possible and let you know about the result -
RE: PYTHON - FIND ANY ID PORT
@zipit Thank you for quick answer !
That's weird 'cause a got this result on R21.207 :
Ports are created as expected...
But I just wonder how I can get the Global matrix and Local matrix ports ID... Still a mistery for me about how I can use any peace of code to get that
-
PYTHON - FIND ANY ID PORT
Hello,
I'm new in python's world. I would like to know what peace of code I can wrhite to get any ID of nodes and nodes' ports.I'm running C4D R21 under MAC OS.
In that case I'm trying to generate global and local matrice ports but it would be nice if I can use this to find any ports I need.
Here is a peace of code I've done, that generates some nodes and ports.I've done some research but I'm a bit confused about how to do it.
import c4d def main(): # Create a null object and add an Xpresso tag to it. null = c4d.BaseList2D(c4d.Onull) null[c4d.ID_BASELIST_NAME] = "ESSAIM - DROTEK-NL" xpresso_tag = c4d.BaseList2D(c4d.Texpresso) null.InsertTag(xpresso_tag) # Crée la texture de référence Led c4d.CallCommand(202586) Ref_Led = doc.GetFirstMaterial() Ref_Led[c4d.MATERIAL_USE_COLOR] = False Ref_Led[c4d.MATERIAL_USE_REFLECTION] = False Ref_Led[c4d.MATERIAL_USE_LUMINANCE] = True Ref_Led[c4d.ID_BASELIST_NAME] = "REF_DROTEK-NL_LED" # Get the node master and the root noode of that graphview. master = xpresso_tag.GetNodeMaster() root = master.GetRoot() # Crée de nouveaux nodes dans l'éditeur python et ouvre les ports nécessaires Hierarchie_node = master.CreateNode(root, c4d.ID_OPERATOR_HIERARCHY, x=10, y=10) Hierarchie_node[c4d.GV_HIERARCHY_START_ID] = "DL" Hierarchie_node[c4d.GV_HIERARCHY_ITERATION_ID] = "P" Indice_objets = master.CreateNode(master.GetRoot(),400001152,None,100,10) ListeDeLiens_node = master.CreateNode(root, c4d.ID_OPERATOR_LINK, x=250, y=10) Obj_Essaim = master.CreateNode(root, c4d.ID_OPERATOR_OBJECT, x=600, y=10) Obj_Essaim.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN, flag = c4d.GV_PORT_FLAG_IS_VISIBLE) Obj_cloner = master.CreateNode(root, c4d.ID_OPERATOR_OBJECT, x=100, y=100) Obj_cloner.AddPort(c4d.GV_PORT_OUTPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_OUT, flag = c4d.GV_PORT_FLAG_IS_VISIBLE) mo_donnee = master.CreateNode(master.GetRoot(),1019010,None,250,100) # Get all in ports of the math node and select the first one. mo_donnee_out = mo_donnee.GetOutPorts() mo_donnee_out = mo_donnee_out[0] if mo_donnee_out else None Obj_Ref_Led = master.CreateNode(root, c4d.ID_OPERATOR_OBJECT, x=600, y=100) Obj_Ref_Led.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN, flag = c4d.GV_PORT_FLAG_IS_VISIBLE) # Lie les ports entre eux """ # Get all out ports of the constant node and select the first one. const_node_out = const_node.GetOutPorts() const_node_out = const_node_out[0] if const_node_out else None # Get all in ports of the math node and select the first one. math_node_in = math_node.GetInPorts() math_node_in = math_node_in[0] if math_node_in else None # Connect the constant node to the math node. if const_node_out and math_node_in: const_node_out.Connect(math_node_in) """ # Add our object to the scene graph and let Cinema update. doc.InsertObject(null) c4d.EventAdd() """liaison des bons objets aux nodes créés.""" # Définition des objets cloner = doc.SearchObject("DROTEK-NL") # Récupère l'objet selon son nom. Rerefence_LED = doc.SearchMaterial("REF_DROTEK-NL_LED") # Récupère le matériaux selon son nom. Obj_cloner[c4d.GV_OBJECT_OBJECT_ID] = cloner # Lie le cloner "DROTEK-NL au Node "cloner" crée précédement. Obj_Ref_Led[c4d.GV_OBJECT_OBJECT_ID] = Rerefence_LED if __name__=='__main__': main()
Can you help me on that point ?
Thank you -
RE: PYTHON - INPUT DELAI
ohh... forgot that !
I'm Working on
- MAC OS 10.14.6
- Cinema 4D R21
-
RE: PYTHON - INPUT DELAI
Hello Zipit,
Thank you a lot for posting advices and answering quit. Your explanations are very precise and clear. Coding might be difficult but offers incredible possibilities. [link text]PYTHON_FIELD_SCRIPT V 0.1.c4dPlease, can you tell me how can I add tags to my post ?
About my project, I think you have a good idea of what I want to do but I'll try to be as precise as possible this time. I attached the scene, it should be easier to understand what I want to do then.
I have 5 "Families" (groups) of clones, determined by the Sphere Fields called "FAMILY_X". Needed for my project evolution.
-
I want them to go from their starting position and morph to FIG_01 which is a grid during a determined time (set into User Data (ex "Transition_time (sec)") of the Python Force Field)
-
For ich family, I want to start the mouvement at a different time (that can be set in User Data (ex "Start_Time // Family_0") of the Python Force Field).
If it is possible with Python Force Field, what code should work to do that ?
If not, what is the best solution to do that ? Python Tag ? Python Script ?
Thank you !
-
-
RE: PYTHON - INPUT DELAI
... I forget one important information : This is a Python Force Field
-
PYTHON - INPUT DELAI
Hello guys,
I started learning Python few days ago and I definitly need help from the pyhton dev community !I wish to insert a "delay time" that can be inputed by the user for each loop I created. How can I do that ?
Here is my code :
import c4d import math import time import threading from c4d.modules import mograph as mo #Welcome to the world of Python Fields def Sample(op, inputs, outputs, info): """Calculate the output values for the specified set of input points. Allocations should be avoided in Sample to maximize performance. Return false on error to cancel sampling. NOTE: Sample function is mandatory, PythonField cannot function without it. Keyword arguments: BaseObject -- the python field. FieldInput -- the points to sample. FieldOutput -- the sampling output arrays (pre-allocated). FieldInfo -- the sampling informations. """ NbObjFamily = 5 flight_time = 5 delay = 5*(doc.GetTime().Get()) # Wave "0" for i in range(0, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = value / flight_time outputs.SetValue(i, offsetValue) # Wave "1" for i in range(1, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Wave "2" for i in range(2, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Wave "3" for i in range(3, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Wave "4" for i in range(4, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Return false to cancel further sampling. return True
Any Idea ?
Thank you