User guide
169
# Create a PrimitiveCreate node at root level
primitive = NodegraphAPI.CreateNode\
( 'PrimitiveCreate', root)
# Create a Merge node at root level
mergeOne = NodegraphAPI.CreateNode( 'Merge', root )
# Add an output port to the PrimitiveCreate node
primOut = primitive.addOutputPort( "newOutputPort" )
# Add an input to the Merge node
mergeIn = mergeOne.addInputPort( "fromPrim" )
# Connect PrimitiveCreate to Merge
primOut.connect( mergeIn )
# Use getConnectedPorts to find connections on mergeIn
mergeInConnected = mergeIn.getConnectedPorts()
# Print the connected port
print( mergeInConnected )
This returns:
[ < Port Producer 'yourPortName' > ]
Logical Source
To find the logical source of an input node use <yourNodeName>.getInputSource(), which takes the name of the
port and a time as arguments, and returns a tuple containing the source port and the time. If no port is found, it
returns None.
For example, recreate the scene shown in Physical and Logical Connections with two nodes connected to the inputs
of a switch node, and one node connected to the output, then find the input source at the output:
root = NodegraphAPI.GetRootNode()
# Create TheInputSourceNode at root level
primitive1 = NodegraphAPI.CreateNode( 'PrimitiveCreate',\
root )
primitive2 = NodegraphAPI.CreateNode( 'PrimitiveCreate',\
root )
primitive1.setName( "A" )
primitive2.setName( "B" )
primitive1Out = primitive1.getOutputPort( "out" )
primitive2Out = primitive2.getOutputPort( "out" )
# Create the Switch node at root level
switch = NodegraphAPI.CreateNode( 'Switch', root )
switchInput1 = switch.addInputPort( "input1" )
switchInput2 = switch.addInputPort( "input2" )
23 NODEGRAPH API | PHYSICAL AND LOGICAL CONNECTIONS