#tool to help figure out whether things on the scene are currently
#being moved by other things either with the editor or by constriants
import maya.cmds as mc
class ConnectionCalculator:
def __init__(self):
"""
no arguments
"""
pass
def isBeingDriven(self,_argument):
"""
returns true if any constraint or connection is on transform
supports any transform, any constraint, or connection
argument can be : element.attribute, or element
assumes attribute is valid name
assumes element is on stage
note even a visibilty connection will count as being driven
add a condition if all connections are just visibilty
"""
argument=_argument
isAttributeDriven = True
listDriver = mc.listConnections(argument,destination=False,source=True)
#listConnections result equals None when empty
if listDriver == None: isAttributeDriven = False
return isAttributeDriven
def isBeingDrivenByVisibilityOnly(self,_transformName):
"""
returns true if only visibility connection is on transform
supports any transform, visbility connection
argument can be : element
assumes element is on stage
"""
transformName = _transformName
isVisibilityDriven = False
visibilityDriverList = mc.listConnections(transformName+'.'+'visibility',destination=False,source=True)
#listConnections result equals None when empty
if visibilityDriverList == None:
isVisibilityDriven = False
else:
allDriverList = mc.listConnections(transformName,destination=False,source=True)
numberOfAllDrivers = len(allDriverList) #should be >= 1
numberOfVisibilityDrivers = len(visibilityDriverList)
#are the same number of visiblity drivers as there all all drivers
if numberOfVisibilityDrivers == numberOfAllDrivers:
isVisibilityDriven = True
return isVisibilityDriven
def isNoConnectOtherVisibility(self, _listTransformName):
"""
returns true if the followin is met for each element
--no connections (constraints/any, component connections/non visibility)
--note return true if any attr locked
--note return true if visibiily connection
cause hiding of controls via group visibility is common on controls
and we still want the tool to work with visibility connections
"""
#default return false
result = False
isConnectedList= []
listTransformName = _listTransformName
numberTransforms = len(listTransformName)
#loop transform
for counterIsConnectedList in range(0,numberTransforms,1):
isBeingDrivenVisibilityOnly = self.isBeingDrivenByVisibilityOnly( listTransformName[counterIsConnectedList] )
#Count visibility connection as no connection
if isBeingDrivenVisibilityOnly == True:
isConnectedList.append(True)
else:
isBeingDriven = self.isBeingDriven( listTransformName[counterIsConnectedList] )
if isBeingDriven == False:
#count not being driven by constraint or by connection as no connection
isConnectedList.append(True)
#if the input list is empty
#if number of trues is same as number of input transforms
if (numberTransforms == 0) | (sum(isConnectedList) == numberTransforms):
result = True
return result