
Search is based on keyword.
Ex: "Procedures"
Do not search with natural language
Ex: "How do I write a new procedure?"
Q100108: Adding custom menu items to the context menu of nodes
SUMMARY
This article describes how to add custom menu items to the context menu (right click menu) of nodes within Katana.
MORE INFORMATION
from Katana import UI4, NodegraphAPI
from UI4.FormMaster.NodeActionDelegate import (BaseNodeActionDelegate, RegisterActionDelegate)
from UI4.Manifest import QtCore, QtGui
class MyNodeActionDelegate(BaseNodeActionDelegate.BaseNodeActionDelegate):
class _SelectNodeAction(QtGui.QAction):
def __init__(self, parent, node):
QtGui.QAction.__init__(self, 'Select "%s"' % node.getName(), parent)
self.__node = node
if node:
QtCore.QObject.connect(self, QtCore.SIGNAL('triggered(bool)'),self.__triggered)
self.setEnabled(self.__node is not None
and not self.__node.isLocked(True))
def __triggered(self, checked):
NodegraphAPI.SetNodeSelected(self.__node, True)
class _DeselectNodeAction(QtGui.QAction):
def __init__(self, parent, node):
QtGui.QAction.__init__(self, 'Deselect "%s"' % node.getName(), parent)
self.__node = node
if node:
QtCore.QObject.connect(self, QtCore.SIGNAL('triggered(bool)'), self.__triggered)
self.setEnabled(self.__node is not None
and not self.__node.isLocked(True))
def __triggered(self, checked):
NodegraphAPI.SetNodeSelected(self.__node, False)
def addToContextMenu(self, menu, node):
menu.addAction(self._SelectNodeAction(menu, node))
menu.addAction(self._DeselectNodeAction(menu, node))
def addToWrenchMenu(self, menu, node, hints=None):
pass
RegisterActionDelegate("CameraCreate", MyNodeActionDelegate())
myNodeActionDelegate = MyNodeActionDelegate()
for nodeTypeName in NodegraphAPI.GetNodeTypes():
RegisterActionDelegate(nodeTypeName, myNodeActionDelegate)
You can also register the same node action delegate against specific node types, as shown in the following example:
myNodeActionDelegate = MyNodeActionDelegate()
for nodeTypeName in ['AttributeSet', 'CameraCreate', 'OpScript']:
RegisterActionDelegate(nodeTypeName, myNodeActionDelegate)
Sorry you didn't find this helpful
Why wasn't this helpful? (check all that apply)
Thanks for your feedback.
If you can't find what you're looking for or you have a workflow question, please try Foundry Support.
If you have any thoughts on how we can improve our learning content, please email the Documentation team using the button below.
Thanks for taking time to give us feedback.