Create VEG
Moving away from Nuke over to the world of Katana I wanted to share a script that I’ve been using to automate a part of the lighting process and save some time.
One of the main powers of Katana is working with VEGs (Variable Enabled Groups ) https://learn.foundry.com/katana/8.0/Content/rg/misc_nodes/variableenabledgroup.html
Using this workflow allows files to stay well organized when making adjustments to specific render layers. Since it’s so powerful you are often creating A LOT of these groups in one file.
If we’re going to be making a lot of them. We better automate the process to avoid user error.
Take your selected nodes and create a VEG using the view flag as the pattern value
#::::::::::::::::::::::::::::
#:::: CREATE VEG ::::
#::::::::::::::::::::::::::::
# Robert Matier
# Version: 1.0.0
# Last Updated: 2025/02/10
# Katana Script designed to create Variable Enable Groups faster
# Works for chains of nodes with simple parent child inputs
# copies selected nodes into a new VEG. Uses the View flag to set the name and the pattern of the VEG
#limitations : node selections with multiple top nodes or bottom nodes cause issue when linking to the VEG ports.
from PyQt5.QtWidgets import QMessageBox
from Katana import NodegraphAPI
def createVEG():
#setup
root = NodegraphAPI.GetRootNode()
pos = NodegraphAPI.GetViewPortPosition(root)
if NodegraphAPI.GetViewNode() != True:
name = NodegraphAPI.GetViewNode().getName()
else:
QtWidgets.QMessageBox(False, 'Viewer Flag', 'Nothing Viewed', QtWidgets.QMessageBox.Ok).exec_()
fullname = name + '_000'
#veg population
newGrp = NodegraphAPI.CreateNode("VariableEnabledGroup", root)
newGrp.setName(fullname)
NodegraphAPI.SetNodePosition(newGrp, (pos[0][0], pos[0][1]))
NodegraphAPI.GetNode(fullname).getParameter('variableName').setValue('passname',0) #update the passname to the string ypu need
NodegraphAPI.GetNode(fullname).getParameter('pattern').setValue(name,0)
newGrp.addInputPort('i0')
newGrp.addOutputPort('o0')
inPort = newGrp.getSendPort('i0')
outPort = newGrp.getReturnPort('o0')
xmlNodes = NodegraphAPI.BuildNodesXmlIO(NodegraphAPI.GetAllSelectedNodes())
toDelete = NodegraphAPI.GetAllSelectedNodes()
newNode = KatanaFile.Paste(xmlNodes, newGrp)[0]
newNodeList = NodegraphAPI.GetAllSelectedNodes()
#find top and bottom nodes respective ports from the list inside the VEG
topNode = None
boottomNode = None
if len(newNodeList) == 1:
listInPort = newNodeList[0].getInputPorts()[0]
listOutPort = newNodeList[0].getOutputPort('out')
else:
for node in newNodeList:
inputPortName = node.getInputPortByIndex(0).getName()
if not node.getInputPorts():
continue
graphState = NodegraphAPI.GetCurrentGraphState()
srcNode = node.getInputSource(inputPortName, graphState)[0]
if srcNode != None:
continue
topNode = node
for node in newNodeList:
outConnection = node.getOutputPortByIndex(0).getNumConnectedPorts()
if outConnection > 0:
continue
bottomNode = node
#cleanup
listInPort = topNode.getInputPorts()[0]
listOutPort = bottomNode.getOutputPort('out')
listOutPort.connect(outPort)
listInPort.connect(inPort)
for i in toDelete:
i.delete()
NodegraphAPI.SetNodeSelected(newGrp, True)
items = NodegraphAPI.GetAllSelectedNodes()
if len(items) == 0:
QtWidgets.QMessageBox(False, 'Selection', 'Nothing selected', QtWidgets.QMessageBox.Ok).exec_()
else:
createVEG()