Search Tips

Search is based on keyword.

`Ex: "Procedures"`

Do not search with natural language

`Ex: "How do I write a new procedure?"`

Give Feedback Support Portal

# Q100494: Renaming Merge node inputs based on incoming node type

Warning: This article contains links to external websites

SUMMARY

When setting up nodes with multiple inputs 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 get tedious.

This article aims to build from the examples given in Q100372: Renaming input and output ports with Python 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 which renames the Merge node input ports based on the category of the connected nodes ( e.g the Merge node input port when connecting a CameraCreate node will be “Camera”, for a NetworkMaterial node 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:

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: Creating a Shelf Item in Katana
Q100402: Editing and removing Shelf Items in Katana

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 review the Katana Online Help and Katana Developer Guide using the links below:

Python connecting nodes: Katana Developer Guide - Working with Nodes - Connecting Nodes
Shelf scripts: Katana Online Help - Scripting with Python - Shelf Item Scripts
SuperTools: Katana Online Help - Developing custom nodes - 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, it creates the new Merge node.

Following on with the Q100372: Renaming input and output ports with Python 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 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:

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

The `checkDictionary()` function iterates through these dictionaries, attempting to find if one of the keys match 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:

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()`:

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 to `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: Editing and removing Shelf Items in Katana

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

- Type_Merge.py(898 KB)