Port creation for a Python Xpresso Node



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/04/2012 at 19:43, xxxxxxxx wrote:

    Hello,

    I've been trying to create ports on a Python node in Xpresso.  I've been able to create other nodes and create ports for them but I haven't been able to create Python ports.  The

      
      master = op.GetNodeMaster()  
      node1 = master.CreateNode(master.GetRoot(),c4d.ID_OPERATOR_OBJECT,None,100,100)  
      node1.AddPort(1, (c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y))  
      op.AddPort(1,c4d.GV_INT)  
    

    In this case I was trying to add an int to the Python node and it isn't working.  I've looked through the SDKs and I couldn't find anything.  Any help would be appreciated.

    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/04/2012 at 01:43, xxxxxxxx wrote:

    Hi Daniel,

    First, I don't understand why you call:

    op.AddPort(1,c4d.GV_INT)
    

    And even if you call:

    node1.AddPort(1,c4d.GV_INT)
    

    If you print what's returned, you get 'None'. Because GvNode.AddPort() expects a valid port ID as second parameter.
    For example you could call:

    node1.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_HISTORY_IN)
    

    You can only add ports IDs defined in the XPresso node container (see GROUP ID_GVPORTS in gvobject.res for the Object operator)

    Also use the available flags name instead of their literal values (c4d.GV_PORT_INPUT instead of 1 for the first parameter of GvNode.AddPort()).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 05/04/2012 at 13:21, xxxxxxxx wrote:

    Thanks for the help. 
    I looked through the gv.res files and I'm hitting a couple new problems.

      
    import c4d  
    #Welcome to the world of Python  
      
      
    def main() :  
       tag = c4d.BaseTag(c4d.Texpresso)  
        
      op.InsertTag(tag)  
      nm = op.GetFirstTag().GetNodeMaster() #Get the node master of selected xpresso tag  
      node1 = nm.CreateNode(nm.GetRoot(),c4d.ID_OPERATOR_OBJECT,insert=None, x=300, y=200) #Create the object's node  
      node2 = nm.CreateNode(nm.GetRoot(),1022471,insert=None, x=300, y=200) #Create python node   
      
      node1.AddPort(c4d.GV_PORT_OUTPUT, c4d.GV_OBJECT_OPERATOR_OLD_GLOBAL_OUT)  
      
      node2.AddPort(c4d.GV_PORT_OUTPUT,c4d.IN_LONG)  
       
      return None  
    

    So any IDs I get from gvobject.res works perfectly fine.  But when I try to use gvpython.res IDs for the Python node it doesn't work.  I've tried the different formatting options that I could think of.  Is there a specific way to use them?  I mainly confused because gvobject.res worked so well.

    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/04/2012 at 08:56, xxxxxxxx wrote:

    node2.AddPort(c4d.GV_PORT_OUTPUT, c4d.IN_LONG)
    

    This code is inconsistent, if you want to add an Integer ouput port to the Python node, you should use OUT_LONG:

    node2.AddPort(c4d.GV_PORT_OUTPUT, c4d.OUT_LONG)
    

    Or if you wanted to add an Integer input port:

    node2.AddPort(c4d.GV_PORT_INPUT, c4d.IN_LONG)
    

    Unfortunately the code doesn't work as expected. This is a know issue with dynamic created ports (multiple port).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/04/2012 at 14:12, xxxxxxxx wrote:

    Thanks for the information.

    This all came out of crating an Xpresso tag through Python and trying to create two object nodes to make the font change on one of them based on a userdata on the other, because the Python code doesn't work in R12.

      
    node = nodemaster.CreateNode(nm.GetRoot(), c4d.ID_OPERATOR_OBJECT,insert=None, x=200, y=200)   
    

    Creates the op's object node, correct?  How would I create object nodes for other objects?
    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/04/2012 at 02:19, xxxxxxxx wrote:

    Yes and you can reference other objects using the operator's c4d.GV_OBJECT_OBJECT_ID container entry:

    node1 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, insert=None, x=200, y=200)
    node1[c4d.GV_OBJECT_OBJECT_ID] = cube
      
    node2 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, insert=None, x=200, y=200)
    node2[c4d.GV_OBJECT_OBJECT_ID] = sphere
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/04/2012 at 18:38, xxxxxxxx wrote:

    Thanks for the help, Yannick.

    Daniel



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 05/09/2012 at 20:01, xxxxxxxx wrote:

    Sorry for resurrecting another dead thread, but it's easier to piggyback off of what other's have already said.

    This is the first time I've created Xpresso nodes with Python, so I'm guessing that I'm missing something simple that my untrained eyes aren't picking up.

    I'm trying to do the following:

    1. Create a hierarchy node and an object node.
    2. Occupy the object node with a nearby cube.
    3. Open up the 'Object' input port on the object node.
    4. Open up the 'Instance' output port on the Hierarchy node. 
    5. Connect the 'Instance' port on hierarchy node with the 'Object' port on the object node.

    Here is what I have so far, currently based on a Python tag for testing before I eventually switch it to an object plug-in. Variable names have been changed for relative readability:

    import c4d
      
    def main() :
        
        # Define Variables
        doc = c4d.documents.GetActiveDocument()
        tagowner = op.GetObject()
        xtag = tagowner.GetFirstTag() # Get Xpresso tag located next to PyTag; plugin will do this more elegantly. 
        master = xtag.GetNodeMaster()
      
        # Check to see if a boolean switch is on
        if tagowner[c4d.ID_USERDATA,1] == 1: 
            
            # Allocate cube object to a variable
            cube = tagowner.GetNext() 
            
            # Create Hieracrchy node and add the output port.
            node_hier = master.CreateNode(master.GetRoot(), c4d.ID_OPERATOR_HIERARCHY, insert=None, x=-30, y=0)               
            node_hier_port_output = node_hier.AddPort(c4d.GV_PORT_OUTPUT,c4d.GV_HIERARCHY_OUTPUT_OBJECT) 
            
            # Create Object node, assign the cube, then add the 'OBJECT IN' port
            node_obj = master.CreateNode(master.GetRoot(), c4d.ID_OPERATOR_OBJECT, insert=None, x=30, y=0)
            node_obj[c4d.GV_OBJECT_OBJECT_ID] = cube
            node_obj_port_instIn = node_obj.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN)
      
            # Connect the ports
            node_hier_port_output.Connect(node_obj_port_instIn)
            
            # Turn the Boolean switch off
            tagowner[c4d.ID_USERDATA,1] = 0 
    

    Result:
    My two nodes are created, the cube fills in the object node, but the object node's input port is not created. I get an error message for line 27 (the line that connects the ports) that says 'NoneType object has no attribute connect'.

    Thank you for your time,
    Luke


Log in to reply