Using Python to create ports on Object nodes



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

    On 07/09/2012 at 09:54, xxxxxxxx wrote:

    C4D R13
    Python

    ------

    I've finished browsing an old PluginCafe post that discusses this concept, but can't seem to figure it out.

    What I CAN do: create an object node in XPresso, and 'fill' it with an object. 
    What I CANNOT do: Create an object port on said node.

    The previously mentioned post says that you can use the IDs used in gvobject.res, in a fashion such as this:

     OBJ_IN = OBJ.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN, flag = c4d.GV_PORT_FLAG_IS_VISIBLE)
    

    However, while this doesn't cause an error to come up in my script, a port is not created - If I try to run a print command on OBJ_IN, I get 'None'. I've tried to create several other ports listed on gvobject.res, but no dice.

    The only port I was able to create was a c4d.ID_BASEOBJECT_POSITION port, but it's an ID not listed in gvobject.res.

    Does anyone know where I might find the correct id for an object port?

    Thanks,
    Luke



  • On 02/01/2013 at 11:42, xxxxxxxx wrote:

    I'm having the exact same problem on that object operator. I even tried setting custom ID's in the gvobject.h file, but nothing. Have you found a solution?

    import c4d
    #Welcome to the world of Python

    def main() :
        
        # create a cube
        cube = c4d.BaseObject(c4d.Ocube)
        # insert cube into scene
        doc.InsertObject(cube)

    # create xpresso tag
        xpressoTag = c4d.BaseTag(c4d.Texpresso)
        # insert xpresso tag to the cube
        cube.InsertTag(xpressoTag)
        
        # get node master
        nodeMaster = xpressoTag.GetNodeMaster()

    # create object node for cube in xpresso
        node1 = nodeMaster.CreateNode(nodeMaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 0, 0)
        node1[c4d.GV_OBJECT_OBJECT_ID] = cube

    # add object out port to node
        port1 = node1.AddPort(c4d.GV_PORT_OUTPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_OUT)
        
        c4d.modules.graphview.RedrawMaster(nodeMaster)
        c4d.EventAdd()
        
        return

    No object out port is created???



  • On 02/01/2013 at 12:21, xxxxxxxx wrote:

    Unfortunately, I'm still in the dark on this one.  :(



  • On 02/01/2013 at 17:39, xxxxxxxx wrote:

    Hmmm, I tried to work around it and create a userdata link -> put the object in the link -> and then pull up the userdata port in the node. Which can be done, see script below. But now the node is highlighting yellow, which still prevents the xpresso set up from working.

    import c4d
    #Welcome to the world of Python

    def main() :
         
        # create a cube
        cube = c4d.BaseObject(c4d.Ocube)
        # insert cube into scene
        doc.InsertObject(cube)
        
        # create a link userdata
        bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BASELISTLINK)
        bc[c4d.DESC_NAME] = "obj"
        linkDataType = cube.AddUserData(bc)
        # set the link userdata
        cube.__setitem__((c4d.ID_USERDATA,1), cube)

    # create xpresso tag
        xpressoTag = c4d.BaseTag(c4d.Texpresso)
        # insert xpresso tag to the cube
        cube.InsertTag(xpressoTag)
         
        # get node master
        nodeMaster = xpressoTag.GetNodeMaster()

    # create object node for cube in xpresso
        node1 = nodeMaster.CreateNode(nodeMaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 0, 0)
        node1[c4d.GV_OBJECT_OBJECT_ID] = cube

    # add userdata out port to node
        port1 = node1.AddPort(c4d.GV_PORT_OUTPUT, (c4d.ID_USERDATA,1))
         
        c4d.modules.graphview.RedrawMaster(nodeMaster)
        c4d.EventAdd()
         
        return

    How can I prevent the node from highlighting yellow? There are no problems creating the nodes and ports manually. Is something wrong with my code?

    thanks



  • On 03/01/2013 at 07:58, xxxxxxxx wrote:

    hey,

    i do not really have a solution for you but nevertheless :

    1. please use code tags ([kode][/kode] - kode written with c of course)

    2. on topic. your code looks fine. i think there is something going wrong in the port creation. i 
    have changed the port type to a less complicated one (suspected first the UserData ID tuple as 
    the culprit) and then used the AddPortIsOk method. It always returns False for me, which i 
    understand as 'something is going really wrong here, but you cannot do anything about it'.

    pid = (c4d.PRIM_CUBE_LEN)
    print node1.AddPortIsOK(c4d.GV_PORT_OUTPUT, pid) # always false
    port1 = node1.AddPort(c4d.GV_PORT_OUTPUT,pid, c4d.GV_PORT_FLAG_IS_VISIBLE, True ) 
    


  • On 25/03/2013 at 04:25, xxxxxxxx wrote:

    Hey everyone. I'm having the exact same problem with AddPort and yellow node. Can please someone say what's wrong?

    import c4d
      
    def main() :
        #new Extrude NURBS
        c4d.CallCommand(5116)
        Nrbs = doc.GetActiveObject()    
        Nrbs[c4d.CAP_START] = Nrbs[c4d.CAP_END] = 3;
        tag = Nrbs.MakeTag(c4d.Texpresso)
        master = tag.GetNodeMaster() 
           
        #new node
        nodeOut = master.CreateNode(master.GetRoot(),c4d.ID_OPERATOR_OBJECT,None,100,100)
        
        #new userdata
        UD = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL);
        UD[c4d.DESC_NAME] = 'fillet';
        add2 = Nrbs.AddUserData(UD);
        Nrbs[add2] = 5;
        
        #outpot port
        nodeOut.AddPort(c4d.GV_PORT_OUTPUT, (c4d.ID_USERDATA, 1));
        
        c4d.EventAdd();
      
    if __name__=='__main__':
        main()
    

    littledevil, I've tried

    nodeOut.AddPort(c4d.GV_PORT_OUTPUT, [c4d.ID_USERDATA,1], c4d.GV_PORT_FLAG_IS_VISIBLE, True )
    

    but hte result is the same



  • On 08/10/2013 at 23:16, xxxxxxxx wrote:

    I haven't revisited this project recently but I found another post that looks promising in regards to the yellow nodes.

    https://plugincafe.maxon.net/topic/7475/9303_port-creation



  • On 24/05/2015 at 16:31, xxxxxxxx wrote:

    Any news on this yet? Surely we can add an object link port to an xpresso node without creating custom userdata!?

    😲



  • On 26/05/2015 at 07:53, xxxxxxxx wrote:

    Hello,

    as discussed earlier there is currently a bug with the object ports. See also this thread:


Log in to reply