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