Q100494: Improve the readability of the node graph by renaming Merge inputs based on incoming node type

Follow

SUMMARY

When setting up nodes with multiple inputs (such as Merge, Switch, or VariableSwitch nodes), it can be useful to rename each input port to indicate which kind of node is connected to it upstream. However, renaming ports manually may become tedious.

This article aims to build on the examples given in Q100372: How to rename input and output ports with Python for clearer connections and provide the functionality to rename the input ports to a Merge node via user-defined categories.

 

MORE INFORMATION

When building a Katana template, it is easier to understand the flow of the template if the input ports display the category of the node they are connected to upstream.

When using the default behaviour of the Merge node, the inputs created are named i0, i1, i2, etc. This naming convention does not provide any information about the connected nodes upstream.

Instead of using the default port names of the Merge node, you could create a custom Python setup that renames the Merge node input ports based on the category of the connected nodes ( e.g the Merge node input port when connected to a CameraCreate node would be “Camera”, for a NetworkMaterial node it would be “Material”).

As an example, adding the functionality to the Merge node could use the following input port names, which would allow for an easier understanding of the upstream setup:

advRename1.PNG

As displayed in the image above, the input ports of the Merge node are renamed according to the category of the nodes connected to each input.

 

EXAMPLE SCRIPT

Attached to this article is a Python example script which can be downloaded and modified for your studio needs.

To have the script working you need to add the attached file to your .katana/Shelves folder location, for example:

Windows: C:\Users\USERNAME\.katana\Shelves\RenameShelf\Type_Merge.py
Linux: /mnt/nethome/users/USERNAME/.katana/Shelves/RenameShelf/Type_Merge.py

For more information on Shelf scripts, please review the following articles:
Q100401: How to create a Shelf Item in Katana to provide easily accessible custom Python scripts
Q100402: How to edit and remove shelf items in Katana to modify existing custom Python scripts

 

USING THE SCRIPT

To test this custom script within Katana you will need to create a selection of nodes ( e.g CameraCreate, PonyCreate and a Material node).

Once the nodes are created, select all of them and use the keyboard shortcut Ctrl+M to merge the nodes using the custom shelf item script. Alternatively, the script can also be accessed by going to the cog icon next to Help and, under Shelf, selecting the RenameShelf shelf action and the Type_Merge shelf item. 

As displayed in the example image above, the Merge node input ports will be named by the category of node they are connected to, as defined in the shelf item script.

The tool is also able to add multiple categories. For example, a ‘PrmanCameraSettings’ node’s Merge port would be named ‘Prman_Camera_Settings’.

For more information on setting up connections, creating shelf items and SuperTools, please check the Katana User Guide and Katana Developer Guide using the links below:

Python connecting nodes: Katana Developer Guide - Working with Nodes - Connecting Nodes
Shelf scripts: Katana User Guide - Scripting and Programming in Katana - Shelf Item Scripts
SuperTools: Katana User Guide - Groups, Macros and SuperTools -  SuperTools

 

SCRIPT EXPLANATION

The script starts by collating the selected nodes (line 80) after the definitions and library variables are set up. Once this data is collected, the new Merge node is created.

Following on with the Q100372: How to rename input and output ports with Python for clearer connections script example, from line 87, the selected nodes are connected to the newly created Merge node by iterating through each selected node in a for loop, which obtains all the output ports of the selected nodes.

The script differs from the example in the Q100372: How to rename input and output ports with Python for clearer connections article by calling a new function checkDictionary() to review user defined dictionaries for specific nodes before adding the input ports.

The custom dictionaries (line 18 to line 44), use the dictionary values to match existing node names (e.g PrimitiveCreate) or potential parts in the node names (e.g Camera), with node category keys used for the input port renaming. 

Here's the MergeType custom dictionary on line 24:

mergeDictionaries.PNG

For example, following the dictionary keys above, a PrimitiveCreate node’s output will be named ‘Geometry’ based on its node category mapping:

mergeDictionaries1.PNG

The checkDictionary() function iterates through these dictionaries, attempting to find if one of the keys matches the selected node’s type. Once a node’s type matches one of the keys, the key is appended to a variable named ‘mergeLabel’, which is used as the name of the input port.

As an example, the ArnoldCameraSettings node will catch 3 of the keys and append them one after another, like so:

advRename2.PNG

The order in which the name components are appended to the final input port name is determined by the order in which the category dictionaries are checked using checkDictionary():

advRename3.PNG

If the calls to checkDictionary() shown above were switched, the input port would be named “Camera_Settings_Arnold” rather than “Arnold_Camera_Settings”.

Following the dictionary formatting, you can add your own custom dictionary and call checkDictionary() to add further components to the input port name.

Once all the input ports have been added, the new Merge node is set as the selected node and is floated in the Node Graph tab through the functions discussed in Q100402: How to edit and remove shelf items in Katana to modify existing custom Python scripts

Floating the Merge node provides the same behaviour as creating a new node.

NOTE: For more clarification on the script, please review the help comments in the script.

 

ATTACHMENTS

We're sorry to hear that

Please tell us why