Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Xpresso Object Index can not connect output ports with Python

    Cinema 4D SDK
    python
    2
    3
    162
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JoelJohera
      last edited by

      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:
      e6cc704c-05a4-4952-b135-8b6323a9f8fe-image.png
      And I am looking for this:
      e4a5ba3b-a2c4-4865-851a-8828a9df120e-image.png
      Also I am using c4d.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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @JoelJohera
        last edited by ferdinand

        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
        7b3fab74-5b9c-4e39-8290-34131b68394a-image.png

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

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • J
          JoelJohera
          last edited by

          Thank you so much

          1 Reply Last reply Reply Quote 0
          • First post
            Last post