# ------------------------------------------------------------------------------------ # gbFindConnection.py - Maya Python Script # ------------------------------------------------------------------------------------ # # DESCRIPTION: # This script prints all the connections of a given selection in the script editor. # It finds both incoming and outgoing connections and ignores the conversion nodes. # This can be useful when Hypergraph isn't collaborating because of the containers. # If conversion nodes are needed change scn=False on lines 37 and 38. # # USAGE: # (PYTHON) import gbFindConnections; gbFindConnections.findConnection() # (MEL) python("import gbFindConnections;gbFindConnections.findConnection()") # # AUTHOR: # Giorgio Bertolone - mail@giorgiobertolone.com - www.giorgiobertolone.com # Copyright (C)2011 - Giorgio Bertolone - All Rights Reserved. # # VERSIONS: # 1.00 - May 01, 2011 - Initial Release # # ------------------------------------------------------------------------------------ import maya.cmds as mc def findConnection(): # check for selection errors and display error messages if there are sel = mc.ls( sl=True ) if len(sel) < 1: mc.confirmDialog( title="Selection Error", message="Nothing is selected. Please select something.", button=["Ok"], defaultButton="Ok" ) if len(sel) > 1: mc.confirmDialog( title="Selection Error", message="More than one selection. Please select only one.", button=["Ok"], defaultButton="Ok" ) if len(sel) == 1: # get source and destination connections on the selection but skip conversion nodes. If you need conversion nodes change scn=False sourcecon = mc.listConnections(sel, s=False, d=True, p=True, c=True, scn=True ) destcon = mc.listConnections(sel, s=True, d=False, p=True, c=True, scn=True ) # print warning message if there are no outgoing connections if len(sel) == 1 and sourcecon is None: print "" print "There are no outgoing connections (from here to somewhere else)." # if there are outgoing connections count how many and display them in the script editor if len(sel) == 1 and sourcecon is not None: numsourcecon = len(sourcecon) / 2 print "" print "----------------------------------------------------------------------------------------------------------" print "" print "TOTAL NUMBER OF OUTGOING CONNECTIONS (FROM HERE TO SOMEWHERE ELSE): %s" % (numsourcecon) print "" for x,y in zip(sourcecon[::2], sourcecon[1::2]): print "" print '%s ---- IS CONNECTED TO ----> %s' % (x,y) # print warning message if there are no incoming connections if len(sel) == 1 and destcon is None: print "" print "There are no incoming connections (from somewhere else to here)." # if there are incoming connections count how many and display them in the script editor if len(sel) == 1 and destcon is not None: numdestcon = len(destcon) / 2 print "" print "----------------------------------------------------------------------------------------------------------" print "" print "TOTAL NUMBER OF INCOMING CONNECTIONS (FROM SOMEWHERE ELSE TO HERE): %s" % (numdestcon) print "" for x,y in zip(destcon[::2], destcon[1::2]): print "" print '%s <---- HAS A CONNECTION FROM ---- %s' % (x,y)