def constraintWithWeightSyntax(*args, **kwargs): """ Maya Bug Fix: - when queried, angle offsets would be returned in radians, not current angle unit Modifications: - added new syntax for querying the weight of a target object, by passing the constraint first:: aimConstraint('pCube1_aimConstraint1', q=1, weight='pSphere1') aimConstraint('pCube1_aimConstraint1', q=1, weight=['pSphere1', 'pCylinder1']) aimConstraint('pCube1_aimConstraint1', q=1, weight=True) """ if kwargs.get('query', kwargs.get('q', False) and len(args) == 1): # Fix the big with angle offset query always being in radians if kwargs.get('offset', kwargs.get('o', None)): return _general.getAttr(str(args[0]) + ".offset") # try seeing if we can apply the new weight query syntax targetObjects = kwargs.get('weight', kwargs.get('w', None)) if targetObjects is not None: # old way caused KeyError if 'w' not in kwargs, even if 'weight' was! # targetObjects = kwargs.get( 'weight', kwargs['w'] ) constraint = args[0] if 'constraint' in cmds.nodeType(constraint, inherited=1): if targetObjects is True or ( # formerly, we allowed 'weight=[]' instead of # 'weight=True' - while this is somewhat more # confusing, continue to support it for backwards # compatibility _util.isIterable(targetObjects) and not targetObjects): targetObjects = func(constraint, q=1, targetList=1) elif _util.isIterable(targetObjects): # convert to list, in case it isn't one targetObjects = list(targetObjects) else: targetObjects = [targetObjects] constraintObj = cmds.listConnections( constraint + '.constraintParentInverseMatrix', s=1, d=0)[0] args = targetObjects + [constraintObj] kwargs.pop('w', None) kwargs['weight'] = True res = func(*args, **kwargs) if kwargs.get('query', kwargs.get('q', False) and len(args) == 1): if kwargs.get('weightAliasList', kwargs.get('wal', None)): res = [ _general.Attribute(args[0] + '.' + attr) for attr in res ] elif kwargs.get('worldUpObject', kwargs.get('wuo', None)): res = _factories.unwrapToPyNode(res) elif kwargs.get('targetList', kwargs.get('tl', None)): res = _factories.toPyNodeList(res) return res
def constraintWithWeightSyntax(*args, **kwargs): """ Maya Bug Fix: - when queried, angle offsets would be returned in radians, not current angle unit Modifications: - added new syntax for querying the weight of a target object, by passing the constraint first:: aimConstraint('pCube1_aimConstraint1', q=1, weight='pSphere1') aimConstraint('pCube1_aimConstraint1', q=1, weight=['pSphere1', 'pCylinder1']) aimConstraint('pCube1_aimConstraint1', q=1, weight=True) """ if kwargs.get('query', kwargs.get('q', False) and len(args) == 1): # Fix the big with angle offset query always being in radians if kwargs.get('offset', kwargs.get('o', None)): return _general.getAttr(str(args[0]) + ".offset") # try seeing if we can apply the new weight query syntax targetObjects = kwargs.get('weight', kwargs.get('w', None)) if targetObjects is not None: # old way caused KeyError if 'w' not in kwargs, even if 'weight' was! # targetObjects = kwargs.get( 'weight', kwargs['w'] ) constraint = args[0] if 'constraint' in cmds.nodeType(constraint, inherited=1): if targetObjects is True or ( # formerly, we allowed 'weight=[]' instead of # 'weight=True' - while this is somewhat more # confusing, continue to support it for backwards # compatibility _util.isIterable(targetObjects) and not targetObjects): targetObjects = func(constraint, q=1, targetList=1) elif _util.isIterable(targetObjects): # convert to list, in case it isn't one targetObjects = list(targetObjects) else: targetObjects = [targetObjects] constraintObj = cmds.listConnections(constraint + '.constraintParentInverseMatrix', s=1, d=0)[0] args = targetObjects + [constraintObj] kwargs.pop('w', None) kwargs['weight'] = True res = func(*args, **kwargs) if kwargs.get('query', kwargs.get('q', False) and len(args) == 1): if kwargs.get('weightAliasList', kwargs.get('wal', None)): res = [_general.Attribute(args[0] + '.' + attr) for attr in res] elif kwargs.get('worldUpObject', kwargs.get('wuo', None)): res = _factories.unwrapToPyNode(res) elif kwargs.get('targetList', kwargs.get('tl', None)): res = _factories.toPyNodeList(res) return res
def constraint(*args, **kwargs): """ Maya Bug Fix: - when queried, upVector, worldUpVector, and aimVector returned the name of the constraint instead of the desired values Modifications: - added new syntax for querying the weight of a target object, by passing the constraint first:: aimConstraint( 'pCube1_aimConstraint1', q=1, weight ='pSphere1' ) aimConstraint( 'pCube1_aimConstraint1', q=1, weight =['pSphere1', 'pCylinder1'] ) aimConstraint( 'pCube1_aimConstraint1', q=1, weight =[] ) """ if kwargs.get( 'query', kwargs.get('q', False) and len(args)==1) : # Fix the big with upVector, worldUpVector, and aimVector attrs = [ 'upVector', 'u', 'worldUpVector', 'wu', 'aimVector', 'a' ] for attr in attrs: if attr in kwargs: return _general.datatypes.Vector( _general.getAttr(args[0] + "." + attr ) ) # ...otherwise, try seeing if we can apply the new weight query syntax targetObjects = kwargs.get( 'weight', kwargs.get('w', None) ) if targetObjects is not None: # old way caused KeyError if 'w' not in kwargs, even if 'weight' was! # targetObjects = kwargs.get( 'weight', kwargs['w'] ) constraint = args[0] if 'constraint' in cmds.nodeType( constraint, inherited=1 ): if not _util.isIterable( targetObjects ): targetObjects = [targetObjects] elif not targetObjects: targetObjects = func( constraint, q=1, targetList=1 ) constraintObj = cmds.listConnections( constraint + '.constraintParentInverseMatrix', s=1, d=0 )[0] args = targetObjects + [constraintObj] kwargs.pop('w',None) kwargs['weight'] = True res = func(*args, **kwargs) if kwargs.get( 'query', kwargs.get('q', False) and len(args)==1) : if kwargs.get( 'weightAliasList', kwargs.get('wal', None) ): res = [_general.Attribute(args[0] + '.' + attr) for attr in res] elif kwargs.get( 'worldUpObject', kwargs.get('wuo', None) ): res = _factories.unwrapToPyNode(res) elif kwargs.get( 'targetList', kwargs.get('tl', None) ): res = _factories.toPyNodeList(res) return res
def constraintWithVectorFix(*args, **kwargs): """ Maya Bug Fix: - when queried, upVector, worldUpVector, and aimVector returned the name of the constraint instead of the desired values """ if kwargs.get( 'query', kwargs.get('q', False) and len(args)==1) : # Fix the big with upVector, worldUpVector, and aimVector attrs = [ 'upVector', 'u', 'worldUpVector', 'wu', 'aimVector', 'a' ] for attr in attrs: if attr in kwargs: return _general.datatypes.Vector( _general.getAttr(str(args[0]) + "." + attr ) ) return constraintWithWeightSyntax(*args, **kwargs)