Skip to content

Instantly share code, notes, and snippets.

@Onefabis
Last active May 10, 2022 13:49
Show Gist options
  • Save Onefabis/0f885ac0627a7e15f706960dfe5f8a5c to your computer and use it in GitHub Desktop.
Save Onefabis/0f885ac0627a7e15f706960dfe5f8a5c to your computer and use it in GitHub Desktop.
Look for any node connections for selected objects in Maya
'''
Select any object and run the script, it will select any node, specified in the list of the "getDG" nType array
Some api node type examples:
Camera = camera
Parent Constraint = parentConstraint
Point Constraint = pointConstraint
Orient Constraint = orientConstraint
Aim Constraint = aimConstraint
Scale Constraint = scaleConstraint
Skin Cluster = skinCluster
Time to unitless anim curve = animCurveTU
Time to angular anim curve = animCurveTA
You can set second argument of the "getDG" to False if you want get any node connected to the transform node
or set it to True if you want get any node connection from the shape node (skinCluster node, for example)
Also you can leave third "getDG" argument Upstream as True to look for any forward connections or change it to False in order to look for backward connections
The last argument is an array that may contain objects that need to checked for connections instead of active selection
for intaance:
constraintNodes = getDG( [ "animCurveTU", "animCurveTA" ], False, False, True, ['pSphere1', 'pSphere2'] )
'''
import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as oma2
def getDG( nType, getShape = False, upstream = True, pluglevel = True, sel=[] ):
kPlugLevel = pluglevel
direction = om2.MItDependencyGraph.kUpstream if upstream else om2.MItDependencyGraph.kDownstream
nodes = []
if len( sel ) == 0:
selection = om2.MGlobal.getActiveSelectionList()
else:
selection = om2.MSelectionList()
for s in sel:
selection.add( s )
for s in xrange( selection.length() ):
if getShape:
mObject = selection.getDagPath( s ).extendToShape().node()
else:
mObject = selection.getDependNode( s )
mItDependencyGraph = om2.MItDependencyGraph( mObject, direction, kPlugLevel, 1 )
while not mItDependencyGraph.isDone():
currentItem = mItDependencyGraph.currentNode()
dependNodeFunc = om2.MFnDependencyNode(currentItem)
if any( [ True for x in nType if x == dependNodeFunc.typeName ] ):
name = dependNodeFunc.name()
nodes.append( name )
mItDependencyGraph.next()
return nodes
constraintNodes = getDG( [ 'parentConstraint' ], False, False, True )
if constraintNodes:
mc.select( constraintNodes, r=1 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment