Author Topic: Connecting specific output pin from PBR base material node  (Read 1744 times)

I'm trying to insert a compnode into an existing SBS between a PBR base material node and an output node (in this case a base color output node), but I'm having a really hard time figuring out the exact syntax to connect a node to the "Base Color" output pin on the PBR base material node. I can see from the docs that I need to set the "aLeftNodeOutput" parameter on the "ConnectNodes" function, but I can't figure out exactly what to put there.

Code: [Select]
aGraph.connectNodes(aLeftNode = PBRNode, aRightNode = myNewInsertedNode, aLeftNodeOutput = ??? )

the docs say that I should be using the "Identifier of the output of the left node", but I'm not sure how to get that. I've tried going through the list of "mCompOutputs" of the PBR node, but uisng the mUID values of those outputs didn't work

anyone have any luck trying to do this?


Yes, get the correct identifier of output can be cumbersome.
Here the various solutions:
- you did the graph (or instance node) so you know the correct identifier name (but here it's not the case =]).

- you can do right-click on the instance node (Base Material) > Open reference > and find the output you want and get the identifier value (the first attributes).

- you can use PySBS to get a list of output identifiers, several way can be use to do that but I think the simplest is:
Code: [Select]
- you can try to "guess" the correct syntax from the label name, We try as much as possible for future substance nodes to keep always the same syntax for identifiers: lowercase without spaces or special chars (ambientocclusion).
But for old ones, usually (for substance nodes) identifier is lower and spaces replaced by nothing or with underscores or camelCase. So for Base Color > basecolor, Specular > specular, Ambient Occlusion > ambientOcclusion.

Hope this can help you.


Last Edit: April 09, 2021, 09:39:14 am

Thank you very much for your response, I've finally had some time to get back to this. the challenge I have is that I don't always know what kind of node is going to be connected to the Base Color output node of the substance. In the example I posted it's a "baseMaterial", but I'm doing this as a batch process on a bunch of substances, and I have no guarantees of the type of the node connected. It could looks like this:

But it could also look something like this:

and I need to be able to programmatically inject some nodes in between those two.

The answer you gave me at least pointed me in a direction to try out a few other things, so I'm posting the solution I came up with for anyone who might run into a similar problem:

"rightNode" is the node who's input I need to modify, in the pictures above it's the "Base Color" output node of the substance:

Code: [Select]
# First get the left node
leftNode =aGraph.getNode(rightNode.getConnectedNodesUID()[0])

# Get an ordered list of all the UIDs for the output pins of the leftNode
listOfOutputIDs = []
for eachPin in leftNode.mCompOutputs :

# Get the UID of the connection to the right node
UIDConnectedToRightNode = rightNode.getConnections()[0].mConnRefOutput

# Get index of the matching UID on the leftNode from the ordered list we built
indexOfLeftOutputPin = listOfOutputIDs.index(UIDConnectedToRightNode )

# Get the identifier for the output pin of the leftnode so we can connect to it
leftPinIdentifier = leftNode.getDefinition().getAllOutputs()[indexOfLeftOutputPin ].mIdentifier

# Actually do the connections to inject newNode in between leftNode and rightNode
aGraph.connectNodes(aLeftNode = leftNode, aRightNode = newNode, aLeftNodeOutput = leftPinIdentifier)
aGraph.connectNodes(aLeftNode = newNode, aRightNode = rightNode)

This works for me now, but currently it assumes the rightNode only has one input connection. If the rightNode had multiple input connections, this could get a lot more annoying. If there's a cleaner way to achieve the same result I'd love to hear about it. Thanks!