Example #1
0
def mirror_getNextIndex(self, side):
    try:
        _str_func = ' mirror_getNextIndex'.format(self)
        log.debug("|{0}| >> ... [{1}]".format(_str_func, self) + '-' * 80)

        l_return = []
        ml_modules = modules_get(self)
        int_lenModules = len(ml_modules)
        str_side = cgmGEN.verify_mirrorSideArg(side)
        for i, mModule in enumerate(ml_modules):
            #self.log.info("Checking: '%s'"%mModule.p_nameShort)
            _str_module = mModule.p_nameShort
            if mModule.get_mirrorSideAsString() == str_side:
                #self.progressBar_set(status = "Checking Module: '%s' "%(_str_module),progress = i, maxValue = int_lenModules)
                try:
                    mi_moduleSet = mModule.rigNull.moduleSet.getMetaList()
                except:
                    mi_moduleSet = []
                for mObj in mi_moduleSet:
                    int_side = mObj.getAttr('mirrorSide')
                    int_idx = mObj.getAttr('mirrorIndex')
                    str_side = mObj.getEnumValueString('mirrorSide')
                    l_return.append(int_idx)
                    l_return.sort()

        if l_return:
            return max(l_return) + 1
        else:
            return 0

    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err)
Example #2
0
def register(
    controlObject=None,  #(mObject - None) -- The object to use as a control
    typeModifier=None,  #(string - None) -- Tag for cgmTypeModifier for naming
    copyTransform=None,  #(mObject - None) -- Object to copy the transform of for our control object
    copyPivot=None,  #(mObject - None) -- Object to copy the pivot of for our control object
    shapeParentTo=None,  #'(mObject - None) -- Object to shape parent our control curve to to use that transform
    useShape=None,  #'(mObject - None) -- Object to use the curve shape of for our control
    setRotateOrder=None,  #'(rotateOrder - None) -- Argument for a rotate order to set
    autoLockNHide=None,  #'(bool - None) -- Try to set lock and hide
    mirrorAxis=None,  #'(string - None) -- Mirror axis to set - using red9's setup terms
    mirrorSide=None,  #'(string/int - None) -- Mirror side - using red9's setup terms
    makeMirrorable=True,  #'(bool - True) -- Setup for mirrorability (using red9) -- implied by other mirror args
    addDynParentGroup=False,  #'(False) -- Add a dynParent group setup
    addExtraGroups=False,  #'(int - False) -- Number of nested extra groups desired
    addConstraintGroup=False,  #'(bool - False) -- If a group just above the control is desired for consraining
    freezeAll=False,  #'(bool - False) -- Freeze all transforms on the control object
    noFreeze=False,
    addSpacePivots=False,  #'(int - False) -- Number of space pivots to generate and connect
    controlType=None,  #'(string - None) -- Tag for cgmType
    aim=None,  #'(string/int - None) -- aim axis to use
    up=None,  #'(string/int - None) -- up axis to use
    out=None,  #'(string/int - None) -- out axis to use
    makeAimable=None,  #'(mObject - False) -- Make object aimable -- implied by aim/up/out):
    **kws):

    _str_func = 'register'
    """
    [{'step':'validate','call':self._validate},
    {'step':'Copy Transform','call':self._copyTransform},
    {'step':'Shape Parent','call':self._shapeParent},
    {'step':'Copy Pivot','call':self._copyPivot},
    {'step':'Naming','call':self._naming},
    {'step':'Aim Setup','call':self._aimSetup},
    {'step':'Rotate Order','call':self._rotateOrder},
    {'step':'Initial Freeze','call':self._initialFreeze},
    {'step':'Groups Setup','call':self._groupsSetup},
    {'step':'Space Pivot','call':self._spacePivots},
    {'step':'Mirror Setup','call':self._mirrorSetup},	                        
    {'step':'Freeze','call':self._freeze},
    {'step':'Mirror Attribute Bridges','call':self._mirrorAttributeBridges_},	                        
    {'step':'lock N Hide','call':self._lockNHide},
    {'step':'Return build','call':self._returnBuild}]
    """
    try:
        #Validate ================================================================================================
        mi_control = cgmMeta.validateObjArg(controlObject,
                                            'cgmControl',
                                            setClass=True)

        str_mirrorAxis = VALID.stringArg(mirrorAxis, calledFrom=_str_func)
        str_mirrorSide = cgmGeneral.verify_mirrorSideArg(
            mirrorSide)  #VALID.stringArg(mirrorSide,calledFrom = _str_func)
        b_makeMirrorable = VALID.boolArg(makeMirrorable, calledFrom=_str_func)

        _addMirrorAttributeBridges = kws.get('addMirrorAttributeBridges',
                                             False)
        addForwardBack = kws.get('addForwardBack', False)

        if _addMirrorAttributeBridges:
            if type(_addMirrorAttributeBridges) not in [list, tuple]:
                raise ValueError, "[Bad addMirrorAttributeBridge arg]{arg: %s}" % _addMirrorAttributeBridge
            for i, l in enumerate(_addMirrorAttributeBridges):
                if type(l) not in [list, tuple]:
                    raise ValueError, "[Bad addMirrorAttributeBridge arg: %s]{arg: %s}" % (
                        i, l)

        # Running lists ------------------------------------------------------------------------------------------
        ml_groups = []  #Holder for groups
        ml_constraintGroups = []
        ml_spacePivots = []

        #Copy Transform ================================================================================================
        if copyTransform is not None:
            mTarget = cgmMeta.validateObjArg(copyTransform,
                                             'cgmObject',
                                             noneValid=True)
            if not mTarget:
                raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyTransform

            #Need to move this to default cgmNode stuff
            mBuffer = mi_control
            i_newTransform = cgmMeta.cgmObject(
                rigging.groupMeObject(mTarget.mNode, False))
            for a in mc.listAttr(mi_control.mNode, userDefined=True):
                ATTR.copy_to(mi_control.mNode, a, i_newTransform.mNode)
            curves.parentShapeInPlace(i_newTransform.mNode,
                                      mi_control.mNode)  #Parent shape
            i_newTransform.parent = mi_control.parent  #Copy parent
            mi_control = cgmMeta.asMeta(i_newTransform,
                                        'cgmControl',
                                        setClass=True)
            mc.delete(mBuffer.mNode)

        #ShapeParent ================================================================================================
        if shapeParentTo:
            i_target = cgmMeta.validateObjArg(shapeParentTo, 'cgmObject')
            CORERIG.shapeParent_in_place(i_target.mNode, mi_control.mNode)
            i_target = cgmMeta.asMeta(i_target, 'cgmControl', setClass=True)
            #mi_control.delete()
            mi_control = i_target  #replace the control with the joint

        if useShape is not None:
            i_shape = cgmMeta.validateObjArg(useShape,
                                             cgmMeta.cgmObject,
                                             mayaType='nurbsCurve')
            curves.parentShapeInPlace(mi_control.mNode, i_shape.mNode)

        #Copy Pivot ============================================================================================
        if copyPivot is not None:
            if issubclass(type(copyPivot), cgmMeta.cgmNode):
                i_target = copyPivot
            elif mc.objExists(copyPivot):
                i_target = cgmMeta.cgmObject(copyPivot)
            else:
                raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyPivot

            #Need to move this to default cgmNode stuff
            mi_control.doCopyPivot(i_target.mNode)

        #Naming ============================================================================================
        mi_control.addAttr('cgmType', 'controlAnim', lock=True)
        if typeModifier is not None:
            mi_control.addAttr('cgmTypeModifier', str(typeModifier), lock=True)
        mi_control.doName()  #mi_control.doName(nameShapes=True)

        #Rotate Order ============================================================================================
        _rotateOrder = False
        if setRotateOrder is not None:
            _rotateOrder = setRotateOrder
        elif controlType in __d_rotateOrderDefaults__.keys():
            _rotateOrder = __d_rotateOrderDefaults__[controlType]
        elif mi_control.getAttr('cgmName') in __d_rotateOrderDefaults__.keys():
            _rotateOrder = __d_rotateOrderDefaults__[mi_control.getAttr(
                'cgmName')]
        else:
            log.debug("|{0}| >> Rotate order not set on: {1}".format(
                _str_func, mi_control.p_nameShort))

        #Set it ---------------------------------------------------------------
        if _rotateOrder:
            mRotateOrder = VALID.simpleOrientation(_rotateOrder)
            #dictionary.validateRotateOrderString(_rotateOrder)

            mc.xform(mi_control.mNode, rotateOrder=mRotateOrder.p_string)

        #Initial Freeze ============================================================================================
        if freezeAll:
            mc.makeIdentity(mi_control.mNode, apply=True, t=1, r=1, s=1, n=0)

        #Groups ============================================================================================
        if addDynParentGroup or addSpacePivots or mi_control.getAttr(
                'cgmName') == 'cog' or _addMirrorAttributeBridges:
            mi_control.addAttr('________________',
                               attrType='int',
                               keyable=False,
                               hidden=False,
                               lock=True)
            ATTR.reorder(mi_control.mNode, '________________', top=True)
        #Aim Setup ============================================================================================
        if aim is not None or up is not None or makeAimable:
            mi_control._verifyAimable()

        #First our master group:
        i_masterGroup = (cgmMeta.asMeta(mi_control.doGroup(True),
                                        'cgmObject',
                                        setClass=True))
        i_masterGroup.doStore('cgmName', mi_control)
        i_masterGroup.addAttr('cgmTypeModifier', 'master', lock=True)
        i_masterGroup.doName()
        mi_control.connectChildNode(i_masterGroup, 'masterGroup', 'groupChild')

        if addDynParentGroup:
            i_dynGroup = (cgmMeta.cgmObject(mi_control.doGroup(True)))
            i_dynGroup = cgmRigMeta.cgmDynParentGroup(dynChild=mi_control,
                                                      dynGroup=i_dynGroup)
            i_dynGroup.doName()
            """
            i_zeroGroup = (cgmMeta.cgmObject(mi_control.doGroup(True)))
            i_zeroGroup.addAttr('cgmTypeModifier','zero',lock=True)
            i_zeroGroup.doName()
            mi_control.connectChildNode(i_zeroGroup,'zeroGroup','groupChild')"""

        if addExtraGroups:
            for i in range(addExtraGroups):
                i_group = (cgmMeta.asMeta(mi_control.doGroup(True),
                                          'cgmObject',
                                          setClass=True))
                if type(
                        addExtraGroups
                ) == int and addExtraGroups > 1:  #Add iterator if necessary
                    i_group.addAttr('cgmIterator', str(i + 1), lock=True)
                    i_group.doName()
                ml_groups.append(i_group)
            mi_control.msgList_connect("extraGroups", ml_groups, 'groupChild')

        if addConstraintGroup:  #ConstraintGroups
            i_constraintGroup = (cgmMeta.asMeta(mi_control.doGroup(True),
                                                'cgmObject',
                                                setClass=True))
            i_constraintGroup.addAttr('cgmTypeModifier',
                                      'constraint',
                                      lock=True)
            i_constraintGroup.doName()
            ml_constraintGroups.append(i_constraintGroup)
            mi_control.connectChildNode(i_constraintGroup, 'constraintGroup',
                                        'groupChild')

        #Space Pivot ============================================================================================
        if addSpacePivots:
            parent = mi_control.getMessage('masterGroup')[0]
            for i in range(int(addSpacePivots)):
                #i_pivot = rUtils.create_spaceLocatorForObject(mi_control.mNode,parent)
                i_pivot = SPACEPIVOTS.create(mi_control.mNode, parent)
                ml_spacePivots.append(i_pivot)
                #log.info("spacePivot created: {0}".format(i_pivot.p_nameShort))

        #Mirror Setup ============================================================================================
        if str_mirrorSide is not None or b_makeMirrorable:
            for mObj in [mi_control] + ml_spacePivots:
                mi_control._verifyMirrorable()
                l_enum = cgmMeta.cgmAttr(mi_control, 'mirrorSide').p_enum
                if str_mirrorSide in l_enum:
                    #log.debug("|{0}| >> Rotate order not set on: {1}".format(_str_func,mi_control.p_nameShort))
                    #log.debug("%s >> %s >> found in : %s"%(_str_funcCombined, "mirrorSetup", l_enum))
                    mi_control.mirrorSide = l_enum.index(str_mirrorSide)
                if str_mirrorAxis:
                    mi_control.mirrorAxis = str_mirrorAxis
            for mObj in mi_control.msgList_get('spacePivots'):
                mObj._verifyMirrorable()
                mi_control.doConnectOut('mirrorAxis',
                                        mObj.mNode + '.mirrorAxis')
                mi_control.doConnectOut('mirrorSide',
                                        mObj.mNode + '.mirrorSide')

                #cgmMeta.cgmAttr(mObj,'mirrorSide').doConnectIn(mi_control,'mirrorSide')
                #cgmMeta.cgmAttr(mi_control,'mirrorAxis').doCopyTo(mObj,connectTargetToSource = 1)
                #ATTR.connect(mObj.mNode + '.mirrorAxis',"{0}.mirrorAxis".format(mi_control.mNode))
                #ATTR.connect(mObj.mNode + 'mirrorSide',"{0}.mirrorSide".format(mi_control.mNode))

        #Freeze ============================================================================================
        if not shapeParentTo and noFreeze is not True:
            if not freezeAll:
                if mi_control.getAttr(
                        'cgmName'
                ) == 'cog' or controlType in __l_fullFreezeTypes__:
                    mc.makeIdentity(mi_control.mNode,
                                    apply=True,
                                    t=1,
                                    r=1,
                                    s=1,
                                    n=0)
                else:
                    mc.makeIdentity(mi_control.mNode,
                                    apply=True,
                                    t=1,
                                    r=0,
                                    s=1,
                                    n=0)
            else:
                mc.makeIdentity(mi_control.mNode,
                                apply=True,
                                t=1,
                                r=1,
                                s=1,
                                n=0)

        #Mirror attriubte Bridges ==========================================================================
        if addForwardBack:
            mPlug_forwardBackDriver = cgmMeta.cgmAttr(mi_control,
                                                      "forwardBack",
                                                      attrType='float',
                                                      keyable=True)
            try:
                mPlug_forwardBackDriven = cgmMeta.validateAttrArg(
                    [mi_control, addForwardBack])['mi_plug']
            except Exception, error:
                raise StandardError, "push pull driver | %s" % (error)

            if str_mirrorSide.lower() == 'right':
                arg_forwardBack = "%s = -%s" % (
                    mPlug_forwardBackDriven.p_combinedShortName,
                    mPlug_forwardBackDriver.p_combinedShortName)
            else:
                arg_forwardBack = "%s = %s" % (
                    mPlug_forwardBackDriven.p_combinedShortName,
                    mPlug_forwardBackDriver.p_combinedShortName)

            mPlug_forwardBackDriven.p_locked = True
            mPlug_forwardBackDriven.p_hidden = True
            mPlug_forwardBackDriven.p_keyable = False
            NodeF.argsToNodes(arg_forwardBack).doBuild()

        if _addMirrorAttributeBridges:
            for l_bridge in _addMirrorAttributeBridges:
                _attrName = VALID.stringArg(l_bridge[0])
                _attrToBridge = VALID.stringArg(l_bridge[1])
                if not mi_control.hasAttr(_attrToBridge):
                    raise StandardError, "['%s' lacks the bridge attr '%s']" % (
                        mi_control.p_nameShort, _attrToBridge)

                mPlug_attrBridgeDriver = cgmMeta.cgmAttr(mi_control,
                                                         _attrName,
                                                         attrType='float',
                                                         keyable=True)
                try:
                    mPlug_attrBridgeDriven = cgmMeta.validateAttrArg(
                        [mi_control, _attrToBridge])['mi_plug']
                except Exception, error:
                    raise StandardError, "[validate control attribute bridge attr]{%s}" % (
                        error)

                if str_mirrorSide.lower() == 'right':
                    arg_attributeBridge = "%s = -%s" % (
                        mPlug_attrBridgeDriven.p_combinedShortName,
                        mPlug_attrBridgeDriver.p_combinedShortName)
                else:
                    arg_attributeBridge = "%s = %s" % (
                        mPlug_attrBridgeDriven.p_combinedShortName,
                        mPlug_attrBridgeDriver.p_combinedShortName)

                mPlug_attrBridgeDriven.p_locked = True
                mPlug_attrBridgeDriven.p_hidden = True
                mPlug_attrBridgeDriven.p_keyable = False
                NodeF.argsToNodes(arg_attributeBridge).doBuild()
Example #3
0
                iSubM_modules = mUI.MelMenuItem(parent,l="Modules(%s)"%(int_lenModules),subMenu = True)
                use_parent = iSubM_modules
                state_multiModule = True
                mUI.MelMenuItem( parent, l="Select",
                             c = cgmUI.Callback(func_multiModuleSelect))
                mUI.MelMenuItem( parent, l="Key",
                             c = cgmUI.Callback(func_multiModuleKey))		
                mUI.MelMenuItem( parent, l="toFK",
                             c = cgmUI.Callback(func_multiDynSwitch,0))	
                mUI.MelMenuItem( parent, l="toIK",
                             c = cgmUI.Callback(func_multiDynSwitch,1))
                mUI.MelMenuItem( parent, l="Reset",
                             c = cgmUI.Callback(func_multiReset))			

            for i_module in self.ml_modules:
                _side = cgmGeneral.verify_mirrorSideArg(i_module.getMayaAttr('cgmDirection') or 'center')
                if state_multiModule:
                    iTmpModuleSub = mUI.MelMenuItem(iSubM_modules,l=" %s  "%i_module.getBaseName(),subMenu = True)
                    use_parent = iTmpModuleSub

                else:
                    mUI.MelMenuItem(parent,l="-- %s --"%i_module.getBaseName(),en = False)
                try:#To build dynswitch
                    i_switch = i_module.rigNull.dynSwitch
                    for a in i_switch.l_dynSwitchAlias:
                        mUI.MelMenuItem( use_parent, l="%s"%a,
                                     c = cgmUI.Callback(i_switch.go,a))						
                except Exception,error:
                    log.info("Failed to build dynSwitch for: %s | %s"%(i_module.getShortName(),error))	
                try:#module basic menu
                    mUI.MelMenuItem( use_parent, l="Key",
Example #4
0
                log.info(i)    
        #Let's look at some progress bar stuff
        def test_ProgressBarSet(self):
            self.log_debug("Debug in test_ProgressBarSet")	    
            for i in self.l_valueBuffer:
                self.progressBar_set(status = ("Getting: '%s'"%i), progress = i, maxValue = self.int_value)
        def test_ProgressBarIter(self):
            self.log_debug("Debug in test_ProgressBarIter")	    	    
            self.progressBar_setMaxStepValue(self.int_value)
            for i in range(self.int_value):
                self.progressBar_iter(status = ("Getting: '%s'"%i))
    return fncWrap(*args, **kws).go()

#Before delving in, let's see what we have in terms of new info 
mySecondFuncCls(printHelp = 1)#...this is a built in that will report registered arg/kw help
cgmGeneral.verify_mirrorSideArg(printHelp = 1)#...let's see a real function

#In your script editor, go History>show stack trace, toggle it on and off and try
mySecondFuncCls('cat')#...note the variance in what's reported

mySecondFuncCls(reportShow = 1)#...take a look at how our report is fleshing out more

valueToPass = 50 # set it in one place so we can play around
mySecondFuncCls(valueToPass)
mySecondFuncCls(valueToPass,setLogLevel = 'debug')#...we can set on the fly
mySecondFuncCls(valueToPass,setLogLevel = 'info')#...or set it back
#Note how much faster log is than print, crazy no?
#==============================================================================================


Example #5
0
		iSubM_modules = MelMenuItem(parent,l="Modules(%s)"%(int_lenModules),subMenu = True)
		use_parent = iSubM_modules
		state_multiModule = True
		MelMenuItem( parent, l="Select",
	                     c = Callback(func_multiModuleSelect))
		MelMenuItem( parent, l="Key",
	                     c = Callback(func_multiModuleKey))		
		MelMenuItem( parent, l="toFK",
	                     c = Callback(func_multiDynSwitch,0))	
		MelMenuItem( parent, l="toIK",
	                     c = Callback(func_multiDynSwitch,1))
		MelMenuItem( parent, l="Reset",
	                     c = Callback(func_multiReset))			
		
	    for i_module in self.ml_modules:
		_side = cgmGeneral.verify_mirrorSideArg(i_module.getMayaAttr('cgmDirection') or 'center')
		if state_multiModule:
		    iTmpModuleSub = MelMenuItem(iSubM_modules,l=" %s  "%i_module.getBaseName(),subMenu = True)
		    use_parent = iTmpModuleSub
			    
		else:
		    MelMenuItem(parent,l="-- %s --"%i_module.getBaseName(),en = False)
		try:#To build dynswitch
		    i_switch = i_module.rigNull.dynSwitch
		    for a in i_switch.l_dynSwitchAlias:
			MelMenuItem( use_parent, l="%s"%a,
		                     c = Callback(i_switch.go,a))						
		except Exception,error:
		    log.info("Failed to build dynSwitch for: %s | %s"%(i_module.getShortName(),error))	
		try:#module basic menu
		    MelMenuItem( use_parent, l="Key",
Example #6
0
        cgmUI.progressBar_end(progressBar)

    return

    #>>>Module control maps ===============================================================================
    for i, mModule in enumerate(ml_modules):
        _str_module = mModule.p_nameShort
        md_data[mModule] = {}  #...Initize a dict for this object
        _d = md_data[mModule]  #...link it
        _d['str_name'] = _str_module

        md, ml = mModule.atUtils('controls_getDat')
        _d['md_controls'] = md
        _d['ml_controls'] = ml  #mModule.rigNull.moduleSet.getMetaList()
        _d['mi_mirror'] = mModule.atUtils('mirror_get')
        _d['str_side'] = cgmGEN.verify_mirrorSideArg(
            mModule.getMayaAttr('cgmDirection') or 'center')

        if _d['str_side'] not in d_runningSideIdxes.keys():
            d_runningSideIdxes[_d['str_side']] = [0]

            #log.infoDict(_d,_str_module)

    #pprint.pprint(vars())
    #return vars()
    return ml_modules
    #>>>Processing ========================================================================================
    ml_processed = []

    #for our first loop, we're gonna create our cull dict of sides of data to then match
    for mModule in ml_modules:
        log.info("|{0}| >> On: {1}".format(_str_func, mModule))