Example #1
0
 def create_attr(self):
     # Create enum attribute on selected control object
     sel = pm.ls(selection=True)
     if not sel:
         pm.displayWarning("Select Control object")
         return None
     attr = self.attr_nm.getText()
     attr_lst = self.enum_val.getText().split("\n")
     enum_attr_val = ""
     for index in range(len(attr_lst)):
         if attr_lst[index]:
             enum_attr_val += attr_lst[index]
             if not index == len(attr_lst) - 1:
                 enum_attr_val += ":"
     for obj in sel:
         pm.addAttr(obj,
                    longName=attr,
                    attributeType="enum",
                    enumName=enum_attr_val,
                    keyable=True,
                    readable=True,
                    storable=True,
                    writable=True)
     self.populate_list()
     return None
Example #2
0
 def initializeSet(self, *args):
     self.vraySettings = pm.PyNode('vraySettings')
     if pm.attributeQuery('deeXVrayFastOptimized', n=self.vraySettings.name(), ex=True):
         self.deeXVrayFastOptimized = True
         self.vraySettings.samplerType.set(1)
         if not pm.attributeQuery('deeXVrayFastLastQuality', n=self.vraySettings.name(), ex=True):
             self.deeXVrayFastLastQuality = 50
             locked = False
             if pm.lockNode(self.vraySettings.name(), query=True, lock=True)[0]:
                 locked = True
                 pm.lockNode(self.vraySettings.name(), lock=False)
             pm.addAttr(self.vraySettings.name(), ln='deeXVrayFastLastQuality', at='long')
             if locked:
                 pm.lockNode(self.vraySettings.name(), lock=True)
             self.vraySettings.deeXVrayFastLastQuality.set(self.deeXVrayFastLastQuality)
         else:
             self.deeXVrayFastLastQuality = self.vraySettings.deeXVrayFastLastQuality.get()
Example #3
0
    def saveSetting(self, *args):
        dicoAttr = {}
        for myAttr in pm.listAttr(self.vraySettings.name()):
            try:
                dicoAttr[myAttr] = pm.getAttr('vraySettings.' + myAttr)
            except:
                OpenMaya.MGlobal.displayInfo('[Arsenal Quality] ' + myAttr + ' value can not be saved or have not value.')

        if not pm.attributeQuery('deeXVrayFastActualSettings', n=self.vraySettings.name(), ex=True):
            locked = False
            if pm.lockNode(self.vraySettings.name(), query=True, lock=True)[0]:
                locked = True
                pm.lockNode(self.vraySettings.name(), lock=False)
            pm.addAttr(self.vraySettings.name(), ln='deeXVrayFastActualSettings', dt='string')
            if locked:
                pm.lockNode(self.vraySettings.name(), lock=True)
        self.vraySettings.deeXVrayFastActualSettings.set(str(dicoAttr))
 def getParentAttr(self, obj, createOnMissing=False, useCurrentIfCreating=False):
     assert isinstance(obj, pymel.core.nodetypes.Transform)
     parAttr = None
     try:
         parAttr = obj.mmmmRiggerIntendedParent
     except:
         ## don't actually create the attribute unless
         if createOnMissing:
             pm.addAttr( obj,
                 ln='mmmmRiggerIntendedParent',
                 at='message'
             )
             parAttr = obj.mmmmRiggerIntendedParent
             if useCurrentIfCreating:
                 parObject = obj.getParent()
                 if not parObject is None:
                     parObj.message >> parAttr
     return parAttr
Example #5
0
def ckAddFidget():
    """
        ckAddFidget( )

        description: this function collects the selected attribute and adds it
          to the list of data that fidget will work with

        inputs: None

        outputs: None

        CK - this would be a great place to add data to a persistent node in the
        maya file(working)
    """

    # fist we are collecting the selected attribute
    atribSel = pm.mel.eval('selectedChannelBoxAttributes();')
    # then we get the object said attribute belongs to
    slectItm = pm.ls( selection = True )
    # the two are added together so we can work with the information
    # inside the maya context
    newAttr =  slectItm.pop() + '.' + atribSel.pop()

    # this is a test to ensure that we are in fact getting some kind of data from
    # the attribute
    newVal = pm.getAttr( newAttr )
    print newVal

    pm.select( clear = True )
    # given that has worked  we will add the data to the lists
    ckAddToList( "ckFidget_GRP.ckFidgetList", newAttr)
    ckAddToList( "ckFidget_GRP.ckFidgetSav", newVal)
    pm.group(name = str(newAttr+"_SAV0" ))
    pm.addAttr( longName="fdgSave", dataType="string", keyable=False)
    newAttr = newAttr.split(".")
    pm.setAttr( str(newAttr[0]+"_"+newAttr[1]+"_SAV0.fdgSave"), str(newVal))
    pm.select( "ckFidget_GRP")
    pm.parent( str(newAttr[0]+"_"+newAttr[1]+"_SAV0") )
    pm.select( clear = True )
    pm.select(newAttr[0])
    # now issue the call to rebuild the interface
    ckFidgetWin()
Example #6
0
 def optimize(self):
     self.deeXVrayFastOptimized = True
     locked = False
     if pm.lockNode(self.vraySettings.name(), query=True, lock=True)[0]:
         locked = True
         pm.lockNode(self.vraySettings.name(), lock=False)
     if not pm.attributeQuery('deeXVrayFastOptimized', n=self.vraySettings.name(), ex=True):
         pm.addAttr(self.vraySettings.name(), ln='deeXVrayFastOptimized', at='bool')
         self.vraySettings.deeXVrayFastOptimized.set(1)
         pm.addAttr(self.vraySettings.name(), ln='deeXVrayFastLastQuality', at='long')
         self.vraySettings.deeXVrayFastLastQuality.set(50)
         pm.addAttr('vraySettings', ln='deeXVrayFastLastTypePreset', dt='string')
         self.vraySettings.deeXVrayFastLastTypePreset.set('deeX_interior')
         pm.addAttr('vraySettings', ln='deeXVrayFastLastPresetPreComp', dt='string')
         self.vraySettings.deeXVrayFastLastPresetPreComp.set('deeX_basic')
         pm.addAttr('vraySettings', ln='deeXVrayFastoptimizationChooserSettings', dt='string')
         self.vraySettings.deeXVrayFastoptimizationChooserSettings.set("{'OptimizationChooserGlobalOptionInt': [False, 0], 'OptimizationChooserImageSamplerInt': [False, 0], 'OptimizationChooserDMCSamplerInt': [False, 0], 'OptimizationChooserIrradianceMapInt': [False, 0], 'OptimizationChooserLightCacheInt': [False, 0], 'OptimizationChooserSystemInt': [False, 0]}")
     if locked:
         pm.lockNode(self.vraySettings.name(), lock=True)
     self.initAttributes()
     self.refresh()
Example #7
0
def treadAtPoints(**kwargs):
    #get inputs
    tread_name = kwargs.get("tr_name", "Tread")
    crv = kwargs.get("path_crv", None)
    crv = str(pm.duplicate(crv, name=str(tread_name) + "PathCrv")[0])
    pm.xform(crv, centerPivots=True)
    #obtain curve length
    full_length = pm.arclen(crv)
    paramVal = []
    uVal = []
    # get param value on the curve at each position selected (locators)
    sel_obj = pm.ls(selection=True)
    for obj in sel_obj:
        pos = pm.xform(obj, query=True, translation=True, worldSpace=True)
        param = getuParamVal(pos, crv)
        paramVal.append(param)
    crv_shp = pm.listRelatives(crv, shapes=True)[0]
    # create arc length dimension tool
    arcLen = pm.arcLengthDimension(crv_shp + ".u[0]")
    # for each param value obtained set the arc length tool attribute and
    # store the length of curve at that param value
    # normalize the curve to obtain the motion path U value at each position
    for val in paramVal:
        pm.setAttr(str(arcLen) + ".uParamValue", val)
        len_at_pos = pm.getAttr(str(arcLen) + ".arcLength")
        uVal.append(len_at_pos / full_length)
    pm.delete(arcLen)
    mthPthLst = []
    jntLst = []
    # create joints, assign motion path and set U value obtained
    for u in uVal:
        pm.select(clear=True)
        jnt = pm.joint()
        jntLst.append(jnt)
        pathanim = pm.pathAnimation(jnt,
                                    curve=crv,
                                    fractionMode=True,
                                    follow=True,
                                    followAxis="x",
                                    worldUpType="vector",
                                    worldUpVector=(0, 1, 0))
        mthPthLst.append(pathanim)
        pm.setAttr(str(pathanim) + ".uValue", u)
        pm.disconnectAttr(str(pathanim) + ".u")
        # create up locator at mid point of all joints
    #loc_pos = midPos(selected_items = jntLst)
    #loc_pos = pm.xform(crv, query=True, translation=True, worldSpace=True)
    loc_pos = midPosVec(objects=jntLst)
    loc = pm.spaceLocator()
    pm.xform(loc, translation=loc_pos, worldSpace=True)
    for mtPth in mthPthLst:
        pm.pathAnimation(mtPth,
                         edit=True,
                         worldUpType="object",
                         worldUpObject=loc)
    # create control curve, add run and speed attributes
    control_crv = pm.circle(name=tread_name + "CTRL",
                            normalX=1,
                            normalY=0,
                            normalZ=0)
    pm.xform(control_crv, translation=loc_pos)
    pm.select(clear=True)
    pm.addAttr(control_crv,
               longName="run",
               attributeType="float",
               keyable=True)
    pm.addAttr(control_crv,
               longName="speed",
               attributeType="float",
               keyable=True,
               minValue=0.0,
               defaultValue=0.5)
    # group the tread setup
    pm.parent(crv, control_crv)
    pm.parent(loc, control_crv)
    pm.select(clear=True)
    gp = pm.group(name=tread_name + "GP")
    pm.select(clear=True)
    jnt_gp = pm.group(jntLst, name=tread_name + "JNTGP")
    pm.xform(gp, translation=loc_pos)
    pm.parent(control_crv, gp)
    pm.parent(jnt_gp, gp)
    createTreadExpression(mtnPth=mthPthLst,
                          runAttr=str(control_crv[0]) + ".run",
                          speedAttr=str(control_crv[0]) + ".speed",
                          exp_nm=tread_name)
    return None


#treadAtPoints(pathCrv = "nurbsCircle1", tr_name = "testTread")
    def makeAnimCtrlAndZero(self, doConnectPosSlave=True, doConnectRotSlave=True):
        ctrls = []
        objs = pm.ls(selection=True)
        for obj in objs:
            
            ## really, you have to find the first occurance of the numbered name
            ## that didn't exist in the scene as either a zero or a control
            goodNumber = None
            iter = 0
            while goodNumber == None   and   iter < 99:
                iter+=1
                if iter==0:
                    foundZ = pm.ls( obj.name() + "_zero" )
                    foundC = pm.ls( obj.name() + "_ctrl" )
                    if len(foundZ)==0  and  len( foundC )==0:
                        goodNumber = 0
                else:
                    foundZ = pm.ls( obj.name() + str(iter) + "_zero" )  ## could use .zfill(2)
                    foundC = pm.ls( obj.name() + str(iter) + "_ctrl" )
                    if len(foundZ)==0  and  len( foundC )==0:
                        goodNumber = iter
        
            if goodNumber == 0:
                basename = obj.name()
            else:
                basename = obj.name() + str(goodNumber)
            
            
            try:
                jointRadius=obj.radius.get()
            except:
                print( traceback.format_exc()  )
                jointRadius=16
            
            radiusToUse = self.ctrlSizeFloatField.getValue()
            if radiusToUse <= 0.0:
                radiusToUse = 8*jointRadius
            ctrlList = pm.circle(normal=[1,0,0], radius=radiusToUse, ch=False)
            #ctrlCircle = ctrlList[1]
            ctrl = ctrlList[0]
            pm.rename( ctrl, basename + "_ctrl" )
            pCon = pm.pointConstraint(
               obj, ctrl
            )
            oCon = pm.orientConstraint(
               obj, ctrl
            )
            ## beware, pymel returns constraints back directly, not in list
            pm.delete( [pCon, oCon] ) ## delte constraints  
        
            zeroList = pm.duplicate( ctrl )
            zero = zeroList[0]
            
            pm.rename( zero, basename + "_zero")
        
        
                
                
        
            pm.delete( zero.getShape() )
            
            pm.parent( ctrl, zero )
            #pCon = pm.pointConstraint( ctrl, obj )
            #oCon = pm.orientConstraint( ctrl, obj ) 

            pm.addAttr( ctrl, ln='posSlave', at='message' )
            pm.addAttr( ctrl, ln='rotSlave', at='message' )
            if doConnectPosSlave==True:
                obj.message >> ctrl.posSlave
            if doConnectRotSlave==True:
                obj.message >> ctrl.rotSlave
                
            ctrls.append( ctrl )
            
        pm.select( ctrls )
Example #9
0
    def _postCreateVirtual(cls, newNode):
        """ This is called before creation, pymel/cmds allowed."""

        pymel.addAttr(newNode, longName='_class', dataType='string')
        newNode._class.set('_JointNode')
Example #10
0
def setup_ik_spline(**kwargs):
    curve = kwargs.get("curve", None)
    joint_chain = kwargs.get("joint_chain", None)
    auto_curve = kwargs.get("auto_curve", True)
    use_curve = kwargs.get("use_curve", None)
    spans = kwargs.get("number_of_spans", 4)
    ctrl_jnts = kwargs.get("num_control_joints", 3)
    ik_name = kwargs.get("ik_name", "ikHandle")
    scale_stretch = kwargs.get("scale_stretch", False)
    create_dense_chain = kwargs.get("dense_chain", False)
    dense_division = kwargs.get("dense_chain_divisions", 3)
    auto_simplify = kwargs.get("auto_simplify_curve", False)
    stretch_exp = kwargs.get("stretch_exp", False)
    global_scale_check = kwargs.get("global_scale_check", False)
    global_scale_attr = kwargs.get("global_scale_attr", None)

    pm.select(joint_chain, hierarchy=True)
    joint_chain = pm.ls(selection=True)
    if not isinstance(joint_chain[0], pm.Joint):
        pm.displayInfo("selection should be of type joint")
        return None
    if len(joint_chain) < 2:
        pm.displayInfo("Chain should consist of more than one joint")
        return None

    if (global_scale_check):
        if (global_scale_attr is None):
            pm.displayInfo("Please input global scale attribute")
            return None
        else:
            obj = global_scale_attr.split(".")[0]
            global_attr = global_scale_attr.split(".")[1]
            check_global_attr = pm.attributeQuery(global_attr,
                                                  node=obj,
                                                  exists=True)
            if not check_global_attr:
                pm.displayInfo("Invalid global scale attribute")
                return None

    start_jnt = joint_chain[0]
    end_joint = joint_chain[-1]

    if create_dense_chain:
        rep_chain = pm.duplicate(joint_chain)
        start_jnt = rep_chain[0]
        end_joint = rep_chain[-1]
        dense_chain(joints=rep_chain, joints_inbetween=dense_division)
        rep_chain.append(end_joint)
        for index in range(len(joint_chain)):
            pm.parentConstraint(rep_chain[index],
                                joint_chain[index],
                                maintainOffset=False)
            #pm.scaleConstraint(rep_chain[index], joint_chain[index], maintainOffset=False)
            pm.connectAttr(
                str(rep_chain[index]) + ".scale",
                str(joint_chain[index]) + ".scale")
        pm.select(start_jnt, hierarchy=True)
        new_chain = pm.ls(selection=True)

    crv = ""

    #print "START", start_jnt
    #print "END",end_joint

    if auto_curve:
        ik_handle, eff, crv = pm.ikHandle(startJoint=start_jnt,
                                          createCurve=auto_curve,
                                          solver="ikSplineSolver",
                                          numSpans=spans,
                                          endEffector=end_joint,
                                          simplifyCurve=auto_simplify)

    else:
        crv = pm.PyNode(use_curve)
        ik_handle, eff = pm.ikHandle(startJoint=start_jnt,
                                     curve=use_curve,
                                     solver="ikSplineSolver",
                                     endEffector=end_joint,
                                     createCurve=False)

    crv.inheritsTransform.set(0)

    pm.rename(ik_handle, ik_name + "IK_Handle")
    pm.rename(crv, ik_name + "IK_Curve")

    ik_curve_shp = crv.getShape()
    crv_info_node = pm.createNode("curveInfo")
    pm.connectAttr(ik_curve_shp + ".worldSpace", crv_info_node + ".inputCurve")
    '''
    if stretch_exp:
        if create_dense_chain:
            stretch_expression(joints = new_chain, curve_info_node = crv_info_node, connect_scale = scale_stretch,
                               expression_name = ik_name+"_stretch_expression")
        else:
            stretch_expression(joints = joint_chain, curve_info_node = crv_info_node, connect_scale = scale_stretch,
                               expression_name = ik_name+"_stretch_expression")
    '''

    if ctrl_jnts:
        if ctrl_jnts == 1:
            print "Minimum 2 joints needed as controllers"
            print "skipping control joint creation process"
            pm.displayInfo("Minimum 2 joints needed as controllers")
        else:
            ctrl_jnts = joints_along_curve(number_of_joints=ctrl_jnts,
                                           curve=crv,
                                           bind_curve_to_joint=True)
            pm.select(clear=True)
            ctr_jnt_gp = pm.group(ctrl_jnts, name="control_joints")
            #print "JNT NAME", ctr_jnt_gp

    if stretch_exp:
        pm.addAttr(ctrl_jnts[-1],
                   longName="Stretch",
                   attributeType="enum",
                   enumName="off:on",
                   keyable=True)
        print "ATTRIBUTE TO", str(ctrl_jnts[-1])
        if create_dense_chain:
            stretch_expression(joints=new_chain,
                               curve_info_node=crv_info_node,
                               connect_scale=scale_stretch,
                               expression_name=ik_name + "_stretch_expression",
                               ctrl_attr=str(ctrl_jnts[-1]) + ".Stretch",
                               glbl_scl_stat=global_scale_check,
                               glbl_scl_attr=global_scale_attr)
        else:
            stretch_expression(joints=joint_chain,
                               curve_info_node=crv_info_node,
                               connect_scale=scale_stretch,
                               expression_name=ik_name + "_stretch_expression",
                               ctrl_attr=str(ctrl_jnts[-1]) + ".Stretch",
                               glbl_scl_stat=global_scale_check,
                               glbl_scl_attr=global_scale_attr)

    final_group = pm.group(name=ik_name + "_ik_group", empty=True)
    pm.parent(joint_chain[0], final_group)
    pm.parent(crv, final_group)
    pm.parent(ik_handle, final_group)
    if ctrl_jnts > 1:
        pm.parent(ctr_jnt_gp, final_group)
    if create_dense_chain:
        pm.select(clear=True)
        dense_grp = pm.group(start_jnt, name="dense_chain_group")
        pm.parent(dense_grp, final_group)

    return None
Example #11
0
    def createCtrl(self, name):
        #cameraName = camera[0].name()
        cameraShape = self.camera.getShape()

        # 그룹 리깅
        constraint = pm.group(n=name + "_constraint", em=True)
        offset = pm.group(n=name + "_offset")
        shakeTransform = pm.group(n=name + "_Shake")
        offsetTz = pm.group(n=name + "_offsetTz")
        offsetTy = pm.group(n=name + "_offsetTy")
        offsetTx = pm.group(n=name + "_offsetTx")
        tz = pm.group(n=name + "_tz")
        rz = pm.group(n=name + "_rz")
        rx = pm.group(n=name + "_rx")
        ry = pm.group(n=name + "_ry")
        ctrl = pm.group(n=name + "_Ctrl")
        pm.setAttr(ctrl + ".displayHandle", 1)
        pm.setAttr(ctrl + ".overrideEnabled", 1)
        pm.setAttr(ctrl + ".overrideColor", 7)  #dark_green

        # Display
        dispGrp = pm.group(n=name + "_Template_Grp", em=1)
        pm.parent(dispGrp, ctrl)
        pm.setAttr(dispGrp + ".overrideEnabled", 1)
        pm.setAttr(dispGrp + ".overrideDisplayType", 1)
        pm.setAttr(dispGrp + ".overrideColor", 7)  #dark_green

        dispNodeList = []
        dispNodeList.extend(self.displayConnect([ctrl, tz]))
        dispNodeList.extend(self.displayConnect([tz, offsetTx]))
        dispNodeList.extend(self.displayConnect([offsetTx, offsetTy]))
        dispNodeList.extend(self.displayConnect([offsetTy, offsetTz]))

        # Outline
        for dispNode in dispNodeList:
            dispNode.rename(name + '_' + dispNode.name())

        pm.parent(dispNodeList, dispGrp)

        # Add attribute
        # Camera attribute
        pm.addAttr(ctrl, ln="Camera", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Camera", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="focalLength",
                   dv=35,
                   at='double',
                   nn="FocalLength (mm)",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="overscan",
                   dv=1,
                   at='double',
                   nn="Overscan",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="frameRange",
                   at='double2',
                   nn="Frame Range (frame)")
        pm.addAttr(ctrl,
                   ln="startFrame",
                   p='frameRange',
                   at='double',
                   nn="Start Frame",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="endFrame",
                   p='frameRange',
                   at='double',
                   nn="End Frame",
                   keyable=True)
        # Tumble attribute
        pm.addAttr(ctrl, ln="Tumble", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Tumble", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="tumbleTranslateZ",
                   at='double',
                   nn="Tumble Translate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="tumbleRotate", at='double3', nn="Tumble Rotate")
        pm.addAttr(ctrl,
                   ln="tumbleRotateX",
                   p='tumbleRotate',
                   at='double',
                   nn="Tumble Rotate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="tumbleRotateY",
                   p='tumbleRotate',
                   at='double',
                   nn="Tumble Rotate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="tumbleRotateZ",
                   p='tumbleRotate',
                   at='double',
                   nn="Tumble Rotate Z",
                   keyable=True)
        # Shake attribute
        pm.addAttr(ctrl, ln="Shake", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Shake", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="time",
                   keyable=False,
                   at='double',
                   nn="Shake Time (second)")
        pm.addAttr(ctrl,
                   ln="timeOffset",
                   keyable=False,
                   at='double',
                   nn="Shake Time Offset (second)")
        pm.addAttr(ctrl, ln="shake1", at='double2', nn=u"Shake 1st (진폭, 주기)")
        pm.addAttr(ctrl,
                   ln="shakeAmplitude1",
                   p='shake1',
                   at='double',
                   nn=u"Shake 1st (진폭)",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeFrequency1",
                   p='shake1',
                   at='double',
                   nn=u"Frequency 1st (주기)",
                   keyable=True)
        pm.addAttr(ctrl, ln="noise1", at='double3', nn="Shake Noise 1st")
        pm.addAttr(ctrl,
                   ln="noise1X",
                   p='noise1',
                   at='double',
                   nn="Shake Noise 1 X")
        pm.addAttr(ctrl,
                   ln="noise1Y",
                   p='noise1',
                   at='double',
                   nn="Shake Noise 1 Y")
        pm.addAttr(ctrl,
                   ln="noise1Z",
                   p='noise1',
                   at='double',
                   nn="Shake Noise 1 Z")
        pm.addAttr(ctrl, ln="shake2", at='double2', nn=u"Shake 2nd (진폭, 주기)")
        pm.addAttr(ctrl,
                   ln="shakeAmplitude2",
                   p='shake2',
                   at='double',
                   nn=u"Shake 2nd (진폭)",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeFrequency2",
                   p='shake2',
                   at='double',
                   nn=u"Frequency 2nd (주기)",
                   keyable=True)
        pm.addAttr(ctrl, ln="noise2", at='double3', nn="Shake Noise 2nd")
        pm.addAttr(ctrl,
                   ln="noise2X",
                   p='noise2',
                   at='double',
                   nn="Shake Noise 2 X")
        pm.addAttr(ctrl,
                   ln="noise2Y",
                   p='noise2',
                   at='double',
                   nn="Shake Noise 2 Y")
        pm.addAttr(ctrl,
                   ln="noise2Z",
                   p='noise2',
                   at='double',
                   nn="Shake Noise 2 Z")
        pm.addAttr(ctrl,
                   ln="shakeTranslate",
                   at='double3',
                   nn="Shake Translate")
        pm.addAttr(ctrl,
                   ln="shakeTranslateX",
                   p='shakeTranslate',
                   at='double',
                   nn="Shake Translate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeTranslateY",
                   p='shakeTranslate',
                   at='double',
                   nn="Shake Translate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeTranslateZ",
                   p='shakeTranslate',
                   at='double',
                   nn="Shake Translate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="shakeRotate", at='double3', nn="Shake Rotate")
        pm.addAttr(ctrl,
                   ln="shakeRotateX",
                   p='shakeRotate',
                   at='double',
                   nn="Shake Rotate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeRotateY",
                   p='shakeRotate',
                   at='double',
                   nn="Shake Rotate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeRotateZ",
                   p='shakeRotate',
                   at='double',
                   nn="Shake Rotate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="shakeScale", at='double', dv=1.0, keyable=True)
        pm.addAttr(ctrl, ln="timeScale", at='double', dv=1.0, keyable=True)
        # Offset attribute
        pm.addAttr(ctrl, ln="Offset", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Offset", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="offsetTranslate",
                   at='double3',
                   nn="Offset Translate")
        pm.addAttr(ctrl,
                   ln="offsetTranslateX",
                   p='offsetTranslate',
                   at='double',
                   nn="Offset Translate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetTranslateY",
                   p='offsetTranslate',
                   at='double',
                   nn="Offset Translate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetTranslateZ",
                   p='offsetTranslate',
                   at='double',
                   nn="Offset Translate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="offsetRotate", at='double3', nn="Offset Rotate")
        pm.addAttr(ctrl,
                   ln="offsetRotateX",
                   p='offsetRotate',
                   at='double',
                   nn="Offset Rotate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetRotateY",
                   p='offsetRotate',
                   at='double',
                   nn="Offset Rotate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetRotateZ",
                   p='offsetRotate',
                   at='double',
                   nn="Offset Rotate Z",
                   keyable=True)
        # Display attribute
        pm.addAttr(ctrl, ln="Display", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Display", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="cameraScale",
                   dv=1,
                   at='double',
                   nn="Camera Scale",
                   keyable=True)
        pm.addAttr(ctrl,
                   en="off:on:",
                   nn="Display Ctrler",
                   ln="displayCtrler",
                   keyable=1,
                   at="enum",
                   dv=1)

        # Connect Attr
        pm.connectAttr(ctrl + ".cameraScale", name + ".sx")
        pm.connectAttr(ctrl + ".cameraScale", name + ".sy")
        pm.connectAttr(ctrl + ".cameraScale", name + ".sz")
        pm.connectAttr(ctrl + ".focalLength", cameraShape + ".focalLength")
        pm.connectAttr(ctrl + ".overscan", cameraShape + ".overscan")
        pm.connectAttr(ctrl + ".tumbleRotateX", rx + ".rx")
        pm.connectAttr(ctrl + ".tumbleRotateY", ry + ".ry")
        pm.connectAttr(ctrl + ".tumbleRotateZ", rz + ".rz")
        pm.connectAttr(ctrl + ".tumbleTranslateZ", tz + ".tz")
        pm.connectAttr(ctrl + ".offsetTranslateX", offsetTx + ".tx")
        pm.connectAttr(ctrl + ".offsetTranslateY", offsetTy + ".ty")
        pm.connectAttr(ctrl + ".offsetTranslateZ", offsetTz + ".tz")
        pm.connectAttr(ctrl + ".offsetRotate", offset + ".r")
        pm.connectAttr(ctrl + ".displayCtrler", dispGrp + ".v")

        # Lock and Hide unused attr
        attrList = [
            "_ry.tx", "_ry.ty", "_ry.tz", "_ry.rx", "_ry.rz", "_ry.sx",
            "_ry.sy", "_ry.sz", "_ry.v", "_rx.tx", "_rx.ty", "_rx.tz",
            "_rx.ry", "_rx.rz", "_rx.sx", "_rx.sy", "_rx.sz", "_rx.v",
            "_rz.tx", "_rz.ty", "_rz.tz", "_rz.rx", "_rz.ry", "_rz.sx",
            "_rz.sy", "_rz.sz", "_rz.v", "_tz.tx", "_tz.ty", "_tz.rx",
            "_tz.ry", "_tz.rz", "_tz.sx", "_tz.sy", "_tz.sz", "_tz.v",
            "_offsetTx.ty", "_offsetTx.tz", "_offsetTx.rx", "_offsetTx.ry",
            "_offsetTx.rz", "_offsetTx.sx", "_offsetTx.sy", "_offsetTx.sz",
            "_offsetTx.v", "_offsetTy.tx", "_offsetTy.tz", "_offsetTy.rx",
            "_offsetTy.ry", "_offsetTy.rz", "_offsetTy.sx", "_offsetTy.sy",
            "_offsetTy.sz", "_offsetTy.v", "_offsetTz.tx", "_offsetTz.ty",
            "_offsetTz.rx", "_offsetTz.ry", "_offsetTz.rz", "_offsetTz.sx",
            "_offsetTz.sy", "_offsetTz.sz", "_offsetTz.v", "_offset.sx",
            "_offset.sy", "_offset.sz", "_offset.v", "_Ctrl.sx", "_Ctrl.sy",
            "_Ctrl.sz"
        ]

        for attr in attrList:
            pm.setAttr(name + attr, lock=True, channelBox=False, keyable=False)
        pm.setAttr(cameraShape + ".orthographic",
                   lock=False,
                   channelBox=False,
                   keyable=True)
        pm.setAttr(cameraShape + ".orthographicWidth",
                   lock=False,
                   channelBox=False,
                   keyable=True)

        # Constraint camera
        const = pm.parentConstraint(constraint,
                                    self.camera,
                                    n=name + '_parentConstraint')
        pm.setAttr(const + ".nds", lock=True, channelBox=False, keyable=False)
        pm.setAttr(const + ".int", lock=True, channelBox=False, keyable=False)
        pm.setAttr(const + ".w0", lock=True, channelBox=False, keyable=False)
        pm.parent(const, ctrl)

        # Add and Connect message
        attr = "camera"
        nodes = [self.camera, ctrl]
        for node in nodes:
            if node.hasAttr(attr):
                node.deleteAttr(attr)
            pm.addAttr(node,
                       ln=attr,
                       multi=1,
                       attributeType="message",
                       indexMatters=False)

        for node in nodes:
            for i in range(0, 2):
                pm.connectAttr('{}.message'.format(nodes[i].name()),
                               '{}.{}[{}]'.format(node.name(), attr, str(i)),
                               f=1)

        # Return
        self.ctrl = ctrl
        uitConvertsion = self.ctrl.outputs(type="unitConversion")
        for uit in uitConvertsion:
            pm.rename(uit.name(), name + '_' + uit.name())

        del self.extNode[:]
        self.extNode.extend([
            constraint, offset, shakeTransform, offsetTz, offsetTy, offsetTx,
            tz, rz, rx, ry, ctrl
        ])
        self.extNode.extend(dispNodeList)
        self.extNode.extend(uitConvertsion)
        pm.select(self.ctrl, r=1)
        return ctrl
    def setup_motion_path(self):
        setup_name = self.get_setup_name()
        path_name = self.get_path_name()
        sample_obj = self.get_sample_objects()
        duplicate_flag = self.get_duplicate_flag()
        placement_type = self.get_placement_type()
        division_count = self.get_division_count()

        if setup_name == self.INVALID_INPUT_FAIL:
            pm.displayError("Invalid Input Entered for setup name")
            return None

        if path_name == self.INVALID_INPUT_FAIL:
            pm.displayError("Invalid Input Entered for path name")
            return None

        if path_name == self.NO_OBJECT_FAIL:
            pm.displayError("path Curve does not exist")
            return None

        if path_name == self.DATA_TYPE_FAIL:
            pm.displayError("Path can be only Nurb Curves")
            return None

        if division_count == self.INVALID_INPUT_FAIL:
            pm.displayError("Invalid Input Entered for divisions")
            return None

        if division_count == self.DATA_TYPE_FAIL:
            pm.displayError("Divisions can take only integer values")
            return None

        if sample_obj == self.NO_OBJECT_FAIL:
            pm.displayError("Sample Object not found")
            return None

        obj_list = []
        path_anim_list = []

        sel_objs = pm.ls(selection=True)

        if duplicate_flag:
            path_name = self.get_duplicate_path(path_crv=path_name)
        path_name = pm.rename(path_name, setup_name + "_path_CRV")

        if placement_type == "uniform":
            obj_list, path_anim_list = self.uniform_distribution(
                name=setup_name,
                path=path_name,
                sample=sample_obj,
                divisions=division_count)
        else:
            if not sel_objs:
                pm.displayError("No Objects selected")
            for obj in sel_objs:
                if not pm.objExists(obj):
                    pm.displayWarning(str(obj), "does not exist")
                    return None
            obj_list, path_anim_list = self.at_selection(
                name=setup_name,
                path=path_name,
                sample=sample_obj,
                selection_list=sel_objs)

        loc_pos = CustomScripts.midPos(selected_items=path_name)
        loc = pm.spaceLocator(name=setup_name + "_up_loc")
        pm.xform(loc, translation=loc_pos)
        control_crv = pm.circle(name=setup_name + "CTRL",
                                normalX=1,
                                normalY=0,
                                normalZ=0)
        pm.xform(control_crv[0], translation=loc_pos, worldSpace=True)
        pm.select(clear=True)
        # add run and speed attributes on parent nurb curve
        pm.addAttr(control_crv[0],
                   longName="run",
                   attributeType="float",
                   keyable=True)
        pm.addAttr(control_crv[0],
                   longName="speed",
                   attributeType="float",
                   keyable=True,
                   minValue=0.0,
                   defaultValue=0.5)
        # edit the existing motion path to assign up locator
        for mtPth in path_anim_list:
            pm.pathAnimation(mtPth,
                             edit=True,
                             worldUpType="object",
                             worldUpObject=loc)
        # parent the setup under the parent nurb curve
        pm.parent(path_name, control_crv[0])
        pm.parent(loc, control_crv[0])
        pm.select(clear=True)
        gp = pm.group(name=setup_name + "GP")
        pm.xform(gp, translation=loc_pos)
        pm.select(clear=True)
        obj_gp = pm.group(obj_list, name=setup_name + "object_GP")
        pm.parent(control_crv[0], gp)
        pm.parent(obj_gp, gp)
        # call to create expression function
        self.createTreadExpression(mtnPth=path_anim_list,
                                   runAttr=str(control_crv[0]) + ".run",
                                   speedAttr=str(control_crv[0]) + ".speed",
                                   exp_nm=setup_name)
        return None
Example #13
0
def ckFidgetInit():
    """
        ckFidgetInit()

        description: this function should initialize ckFidget
            it should check for existing persistent data
            and create a new node if none exists
            then it creates the interface

        inputs: None

        outputs: initializes ckFidget
    """
    try:
        print "checking for persistent fidget data"
        pm.select("ckFidget_GRP")
        isFidget = pm.getAttr("ckFidget_GRP.ckIsFidget")
        if isFidget == True:
            print "Data Found!"
            pm.setAttr("ckFidget_GRP.bumpBy", False)
    except:
        print "data not found initializing new ckFidget instance"
        pm.group(empty=True, name="ckFidget_GRP")
        pm.addAttr( longName="ckIsFidget", attributeType='bool', keyable=False )
        pm.setAttr("ckFidget_GRP.ckIsFidget", True)
        pm.addAttr( longName="bumpBy", attributeType='bool', keyable=False )
        pm.setAttr("ckFidget_GRP.bumpBy", False)
        pm.addAttr( longName="ckFidgetBump", attributeType='float', keyable=False, defaultValue=0.1 )
        pm.addAttr( longName="numSaves", attributeType="short", keyable=False, defaultValue=0 )

        print "here is where I should ask about starting a new fidget"
        # should pop up a dialog and ask the name of the new fidget
        pm.addAttr( longName="ckFidgetList", dataType='string', keyable=False )
        pm.addAttr( longName="ckFidgetSav", dataType='string', keyable=False )
        pm.setAttr( "ckFidget_GRP.ckFidgetList","" )
        pm.setAttr( "ckFidget_GRP.ckFidgetSav","" )
        pm.select( clear = True )
    ckFidgetWin()
def createTread(**kwargs):
    # get inputs
    divisions = kwargs.get("no_of_joints", 0)
    tread_name = kwargs.get("tr_name", "Tread")
    path_crv = kwargs.get("path_crv", None)
    # duplicate the existing curve to use for tread creation
    path_crv = str(pm.duplicate(path_crv, name=str(tread_name) + "PathCrv")[0])
    pm.xform(path_crv, centerPivots=True)
    count = 0
    part = float(1) / float(divisions)
    init = 0
    path_anim_list = []
    jnt_lst = []
    # create joints and place them on curve using motion path at equal distance
    while count < divisions:
        pm.select(clear=True)
        jnt = pm.joint()
        jnt_lst.append(jnt)
        pathanim = pm.pathAnimation(jnt,
                                    curve=path_crv,
                                    fractionMode=True,
                                    follow=True,
                                    followAxis="x",
                                    worldUpType="vector",
                                    worldUpVector=(0, 1, 0))
        path_anim_list.append(pathanim)
        pm.setAttr(str(pathanim) + ".uValue", init)
        pm.disconnectAttr(str(pathanim) + ".u")
        init += part
        count += 1
        # obtain the midpoint of all joints to create an up locator and position it at midpoint
    #loc_pos = midPos(selected_items = jnt_lst)
    #loc_pos = pm.xform(path_crv, query=True, translation=True, worldSpace=True)
    loc_pos = midPosVec(objects=jnt_lst)
    loc = pm.spaceLocator(name=tread_name + "_up_loc")
    pm.xform(loc, translation=loc_pos)
    # create a nurb circle to act as parent controller
    control_crv = pm.circle(name=tread_name + "CTRL",
                            normalX=1,
                            normalY=0,
                            normalZ=0)
    pm.xform(control_crv, translation=loc_pos)
    pm.select(clear=True)
    # add unr and speed attributes on parent nurb curve
    pm.addAttr(control_crv,
               longName="run",
               attributeType="float",
               keyable=True)
    pm.addAttr(control_crv,
               longName="speed",
               attributeType="float",
               keyable=True,
               minValue=0.0,
               defaultValue=0.5)
    #edit the existing motion path to assign up locator
    for mtPth in path_anim_list:
        pm.pathAnimation(mtPth,
                         edit=True,
                         worldUpType="object",
                         worldUpObject=loc)
    #parent the setup under the parent nurb curve
    pm.parent(path_crv, control_crv)
    pm.parent(loc, control_crv)
    pm.select(clear=True)
    gp = pm.group(name=tread_name + "GP")
    pm.select(clear=True)
    jnt_gp = pm.group(jnt_lst, name=tread_name + "JNTGP")
    pm.xform(gp, translation=loc_pos)
    pm.parent(control_crv, gp)
    pm.parent(jnt_gp, gp)
    # call to create expression function
    createTreadExpression(mtnPth=path_anim_list,
                          runAttr=str(control_crv[0]) + ".run",
                          speedAttr=str(control_crv[0]) + ".speed",
                          exp_nm=tread_name)
    return None