Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active August 3, 2017 04:20
Show Gist options
  • Save patwooky/243ddecce1dac5e80c89ac69c968b5a2 to your computer and use it in GitHub Desktop.
Save patwooky/243ddecce1dac5e80c89ac69c968b5a2 to your computer and use it in GitHub Desktop.
Maya Python script. Hides the transform nodes of types that are not selected
import maya.cmds as mc
def hideDeselectedNodeType(targetNodeType):
# selectedNodeTransforms will contain transform nodes
# of all target node type shapes that are selected
selectedNodeTransforms = []
for selNode in mc.ls(sl=True):
if targetNodeType in mc.nodeType(selNode):
# selected node is the correct type
# add the transform node to selectedNodeTransforms
selectedNodeTransforms.append(mc.listRelatives(selNode, parent=True))
elif mc.listRelatives(selNode, children=True, type=targetNodeType):
# selected node is a transform node
# with a child node of the correct type
# add the transform node to selectedNodeTransforms
selectedNodeTransforms.append(selNode)
if selectedNodeTransforms:
# only if something is selected, do the hiding thing.
# if we do not do this check,
# all transform of targetNodeType will be hidden
print 'selected objects:',selectedNodeTransforms
for thisNode in mc.ls(type=targetNodeType):
# loops through all target shapes in the scene
# get the transform node
thisNodeTransform = mc.listRelatives(thisNode, parent=True)[0]
if not thisNodeTransform in selectedNodeTransforms:
print 'hiding', thisNodeTransform
hide(thisNodeTransform)
else:
print 'nothing is selected'
hideDeselectedNodeType('camera')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment