Xpresso Object Index can not connect output ports with Python
-
To whom it may concern,
I am trying to connect the outputs of an Object Index Node to other nodes. I know it can be done as via the GUI I can do it but I can not do it with Python.
This is the code I have:import c4d def main(): doc = c4d.documents.GetActiveDocument() null = doc.SearchObject("Null") sphere = null.GetDown() xtag = c4d.BaseTag(c4d.Texpresso) null.InsertTag(xtag) gv = xtag.GetNodeMaster() # Object Index Node object_index_node = gv.CreateNode(gv.GetRoot(), c4d.ID_OPERATOR_DETAILS) object_index_node_in_instance = object_index_node.GetInPorts()[0] object_index_node_out_index = object_index_node.GetOutPorts()[0] object_index_node_out_instance = object_index_node.GetOutPorts()[1] # Sphere Node sphere_node = gv.CreateNode(gv.GetRoot(), c4d.ID_OPERATOR_OBJECT) sphere_node[c4d.GV_OBJECT_OBJECT_ID] = sphere sphere_node_in_object = sphere_node.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN) # Motion Data Node motion_data_node = gv.CreateNode(gv.GetRoot(), 1019010) motion_data_node_in_index = motion_data_node.GetInPorts()[0] motion_data_node_in_object = motion_data_node.GetInPorts()[1] # Connections object_index_node_out_instance.Connect(sphere_node_in_object) print(object_index_node_out_instance) object_index_node_out_index.Connect(motion_data_node_in_index) print(object_index_node_out_index) c4d.EventAdd() if __name__=='__main__': main()
In the console, I get:
False False
I get this:
And I am looking for this:
Also I am usingc4d.ID_OPERATOR_DETAILS
to generate the node as in__init__.py
matched the 400001152 number that the node has if it is created via the GUI.
Thank you for your time.
Joel Johera -
Hey @JoelJohera,
your code simply contains a bug, you are using the wrong indices when you blindly index into the lists of ports.
Cheers,
Ferdinand
import c4d def main(): doc = c4d.documents.GetActiveDocument() null = doc.SearchObject("Null") sphere = null.GetDown() xtag = c4d.BaseTag(c4d.Texpresso) null.InsertTag(xtag) gv = xtag.GetNodeMaster() # Object Index Node object_index_node = gv.CreateNode(gv.GetRoot(), c4d.ID_OPERATOR_DETAILS) object_index_node_in_instance = object_index_node.GetInPorts()[0] object_index_node_out_index = object_index_node.GetOutPorts()[1] # You had the wrong indices here ... object_index_node_out_instance = object_index_node.GetOutPorts()[0] # ... and here. # Using indices the find ports is always a bit risky, because the user can reorder them. # Sphere Node sphere_node = gv.CreateNode(gv.GetRoot(), c4d.ID_OPERATOR_OBJECT) sphere_node[c4d.GV_OBJECT_OBJECT_ID] = sphere sphere_node_in_object = sphere_node.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN) # Motion Data Node motion_data_node = gv.CreateNode(gv.GetRoot(), 1019010) motion_data_node_in_index = motion_data_node.GetInPorts()[0] motion_data_node_in_object = motion_data_node.GetInPorts()[1] # Connections object_index_node_out_instance.Connect(sphere_node_in_object) print(object_index_node_out_instance) object_index_node_out_index.Connect(motion_data_node_in_index) print(object_index_node_out_index) c4d.EventAdd() if __name__=='__main__': main()
-
Thank you so much