@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()