示例#1
0
def lock (attr, node = None):
    '''
    Lock attributes

    .. python ::
        lock ("testMe.translateX")

    @param attr: Attribute name(s) or path(s)
    @type attr: *str* or *list*

    @param node: Attribute parent node(s)
    @type node: *str*
    '''
    # Resolve arguments to
    attrList = common.toList (attr)
    nodeList = common.toList (node)

    # Loop through nodes
    for node in nodeList:
        # Loop through attributes
        for attr in attrList:
            # Resolve attribute
            attrPath, attrName, attrNode = resolveArgs (attr, node)

            # Lock attributes
            cmds.setAttr(attrPath, lock = True)
示例#2
0
def attrNodeList(attr, node):
    #Get list of nodes and attrs
    attrList = common.toList(attr)
    nodeList = common.toList(node)

    #declare function list varaibles
    attrs = list()
    nodes = list()

    #check for nodes
    if not nodeList:
        for attr in attrList:
            attrName, attrPath, attrNode = resolveArgs(attr)
            attrs.append(attrName)
            nodes.append(attrNode)
    else:
        for node in nodeList:
            for attr in attrList:
                attrName, attrPath, attrNode = resolveArgs(attr, node)
                if not attrName in attrs:
                    attrs.append(attrName)
                if not attrNode in nodes:
                    nodes.append(attrNode)

    return attrs, nodes
示例#3
0
文件: rig.py 项目: jonntd/japeto
    def saveJoints(cls, joints, filepath):
        """
        Save the joints for the asset
        
        :param joints: joints that will be written out
        :type joints: list | str | tuple
        """
        # declare list that will be used to gather controls to save
        savedJoints = list()
        # make sure controls is a list before proceeding
        joints = common.toList(joints)

        if not isinstance(joints, list):
            raise RuntimeError("%s must be a list" % joints)
        # end if

        for jnt in joints:
            if common.isValid(jnt):
                if common.isType(jnt, "joint"):
                    savedJoints.append(jnt)
            # end if
        # end loop

        # save the controls in savedControls list
        joint.save(savedJoints, filepath=filepath)
示例#4
0
文件: rig.py 项目: jonntd/japeto
    def saveControls(cls, controls, filepath):
        """
        Save the controls for the asset
        
        :param controls: controls that will be written out 
                        if they're nurbsCurves
        :type controls: list | str | tuple
        """
        # declare list that will be used to gather controls to save
        savedControls = list()
        # make sure controls is a list before proceeding
        controls = common.toList(controls)

        if not isinstance(controls, list):
            raise RuntimeError("%s must be a list" % controls)
        # end if

        for ctrl in controls:
            if common.isValid(ctrl):
                if common.isType(ctrl, "nurbsCurve") or common.isType(common.getShapes(ctrl, 0), "nurbsCurve"):
                    savedControls.append(ctrl)
            # end if
        # end loop

        # save the controls in savedControls list
        control.save(savedControls, filepath=filepath)
示例#5
0
def copy(attr, node = None, destination = None, connect = False, reverseConnect = True, newName = None):
    '''
    Copy attribute to another object

    @param attr: Attribute name(s) or path(s)
    @type attr: *str* or *list*

    @param node: Attribute parent node
    @type node: *str*

    @param destination: Attribute destination node
    @type destination: *str*

    @param connect: Connect copied attributes to original
    @type connect: *bool*

    @param newName: New attribute name
    @type newName: *str*

    @return: Return copy attribute path
    @rtype: *str*
    '''
    attrList = common.toList(attr)

    for attr in attrList:
        attrPath, attrName, attrNode = resolveArgs(attr, node)

        attrType = cmds.getAttr(attrPath, type = True)

        # Get default value
        defValue = cmds.addAttr (attrPath, query = True, defaultValue = True)

        # Get enum items 
        if attrType == 'enum':
            defValue = cmds.attributeQuery( attr, node = attrNode, listEnum=True)[0].split(':')

        # Add new attribute
        if newName != None:
            copyAttr = addAttr (destination, newName, attrType = attrType, defValue = defValue, min = getAttrMin(attrPath), max = getAttrMax(attrPath))
        else:
            copyAttr = addAttr (destination, attrName, attrType = attrType, defValue = defValue, min = getAttrMin(attrPath), max = getAttrMax(attrPath))

        # Set visibility
        keyable    = cmds.getAttr( attrPath, keyable=True )
        channelBox = cmds.getAttr( attrPath, channelBox=True )
        cmds.setAttr( copyAttr, keyable=keyable, channelBox=channelBox )
        # connect
        if connect:
            # Connect new attribute to old
            cmds.connectAttr(copyAttr, attrPath, f = True)
        elif reverseConnect:
            # Connect old attribute to new
            cmds.connectAttr(attrPath, copyAttr, f = True)
        else:
            # Copy attribute value
            cmds.setAttr(copyAttr, cmds.getAttr(attrPath))

    # Return new attribute path
    return copyAttr
示例#6
0
def hide(attr, node = None):
    attrList = common.toList (attr)
    nodeList = common.toList (node)

    #loop through nodes
    for node in nodeList:
        # Loop through attributes
        for attr in attrList:
            # Resolve attribute
            attrPath, attrName, attrNode = resolveArgs (attr, node)
            # Get attribute children
            attrChildren = cmds.attributeQuery (attrName, node = attrNode, listChildren = True)

            # Check if attribute has any children
            if attrChildren:
                for childAttr in attrChildren:
                    # Hide attribute
                    cmds.setAttr ("%s.%s" % (attrNode, childAttr), keyable = False)

            else:
                cmds.setAttr(attrPath, keyable = False )
示例#7
0
文件: joint.py 项目: jonntd/japeto
def save( node, filepath=None ):
    '''Save the following attributes from the joint: translate, rotate, scale, rotateAxis, rotateOrder, jointOrient, radius, drawStyle, parent


    .. python ::
        save( 'joint1' )
        # Result: "/var/tmp/joints.pyson"

        save( cmds.ls( type='joint'), '/var/tmp/bipedSkeleton.joints' )
        # Result: "/var/tmp/bipedSkeleton.joints"
    
    :param node: Node(s) you want to export
    :type node: **str** or **list**
    :param filepath: Filepath to save the file. If None will use the OS temporary directory.
    :type filepath: **str** or **list**
    '''

    # Get filepath
    if filepath == None:
        filepath = os.path.join( tempfile.gettempdir(), 'joints.pyson' )
    
    # Get nodes
    data  = ordereddict.OrderedDict()
    nodes = common.toList( node )

    # Loop through nodes
    for node in nodes:
        
        # Check object
        if not cmds.objectType( node ) == 'joint':
            continue
        
        # Node entries
        data[node] = ordereddict.OrderedDict()
        data[node]['parameters']  = ordereddict.OrderedDict()

        # Store transformation
        for attr in ['translate', 'rotate', 'scale', 'rotateAxis', 'jointOrient', 'rotateOrder', 'radius', 'drawStyle']:
            if attribute.isCompound(attr, node ):
                data[node]['parameters'][attr] = attribute.getValue( attr, node )[0]
            else:
                data[node]['parameters'][attr] = attribute.getValue( attr, node )
        
        # Store parent
        data[node]['parent'] = common.getParent( node )

        # World Position
        data[node]['worldPosition'] = cmds.xform( node, q=True, ws=True, rp=True )
        
    # Save data
    pyon.save( data, filepath )
    return filepath
示例#8
0
文件: spine.py 项目: jonntd/japeto
 def _ikControlSetup(self, drivers):
     '''
     Takes driver joints that drive the IK spine and create controls for them
     
     @param drivers: list of drivers you want to put controls on
     @type drivers: *list* or *tuple* or *str* 
     
     @return: IK controls which were created to drive the driver joints passed in
     @rtype: *list*
     '''
     #create an empty list to store ik controls in so we can return them
     ikControls = list()
     
     drivers = common.toList(drivers)
     
     for i,driver in enumerate(drivers):
         nameDescription = common.getDescription(driver)
         ctrlName = '%s_%s_%s' % (self._getSide(),nameDescription,common.IK)
         ctrl = control.create(ctrlName, type = 'cube',
                               parent = self.controlsGrp,
                               color = common.SIDE_COLOR[self._getSide()])
         ctrlZero = common.getParent(ctrl)
         #driverParent = common.getParent(driver)
         #move control in to position of driver jnt
         transform.matchXform(driver, ctrlZero, 'pose')
         #cmds.parent(ctrlZero, driverParent)
         #cmds.parent(driver, ctrl)
         cmds.parentConstraint(ctrl, driver,mo = True)
         
         
         #connect ik/fk attr from group to  visibility of shapes
         reverse = cmds.createNode('reverse', n = '%s_%s_%s' % (self.name(),
                                                             common.IK,
                                                             common.REVERSE
                                                             ))
         attribute.connect('%s.ikfk' % self.ikFkGroup,'%s.inputX' % reverse)
         for shape in common.getShapes(ctrl):
             if self.ikFkGroup:
                 attribute.connect('%s.outputX' % reverse,
                                   '%s.v' % shape)
             #end if
         #end loop
         
         ikControls.append(ctrl)
         
         
         
     #end loop
         
     return ikControls
     
示例#9
0
def lockAndHide(attr, node = None):
    '''
    Locks and hides specified attributes

    '''
    attrList = common.toList(attr)

    for attr in attrList:
        if node:
            lock(attr, node)
            hide(attr, node)
            continue

        attrPath, attrName, attrNode = resolveArgs (attr, node)
        lock(attrPath)
        hide(attrPath)
示例#10
0
文件: chain.py 项目: jonntd/japeto
    def _fkControlSetup(self, joints):
        '''
        Creates FK control setup on the input joints
        
        Example:
            ...python:
                    self._fkControlSetup(["jnt1", "jnt2", "jnt3"])
                    #Return: ["ctrl1", "ctrl2", "ctrl3"]
                    
        :param joints: Joints to have controls drive
        :type joints: *list* or *tupple* or *str*
        
        
        '''
        joints = common.toList(joints)
        
        if not isinstance(joints, list) and not isinstance(joints, tuple):
            raise RuntimeError('%s must be a *list* or *tuple*' % joints)
        
        fkCtrls = list()
        parent = self.controlsGrp

        for jnt in joints:            
            ctrl = control.create(name= jnt.split('_%s' % common.JOINT)[0],
                    type = 'circle',
                    parent = parent,
                    color = common.SIDE_COLOR[self._getSide()])

            ctrlParent = common.getParent(ctrl)
            transform.matchXform(jnt, ctrlParent, type = 'pose')
            cmds.parentConstraint(ctrl, jnt, mo = True) #----> might change this to connect rotations and not use translation
            
            #connect visibility of shapes to foot control
            for shape in common.getShapes(ctrl):
                if self.ikFkGroup:
                    attribute.connect('%s.ikfk' % self.ikFkGroup,
                                      '%s.v' % shape)
                #end if
            #end loop

            parent = ctrl
            fkCtrls.append(ctrl)
        #end loop
            
        return fkCtrls
示例#11
0
文件: joint.py 项目: jonntd/japeto
def mirror (joint, search = common.LEFT, replace = common.RIGHT, axis = "x"):
    '''
    Mirror joint orientation
    It won't create a new joint, it will only mirror the oriention from one existing joint to another.

    .. python ::

        mirror( cmds.ls(sl=True) )

    :param joint: Joint you want to mirror
    :type joint: *str* or *list*

    :param search: Search side token
    :type search: *str*

    :param replace: Replace side token
    :type replace: *str*

    :param axis: Mirror plane axis, for example **x**
    :type axis: *str*
    '''

    # get given joints
    joints = common.toList(joint)

    # get selection
    selection = cmds.ls(sl=True)

    posVector = ()
    oriVector = ()
    if axis.lower() == 'x':
        posVector = (-1,1,1)
        oriVector = (0,180,180)
    elif axis.lower() == 'y':
        posVector = (1,-1,1)
        oriVector = (180,0,180)
    elif axis.lower() == 'z':
        posVector = (1,1,-1)
        oriVector = (180,180,0)

    for i in range(len(joints)):

        obj1 = joints[i]
        obj2 = joints[i].replace( search, replace )

        if cmds.objExists(obj1) and cmds.objExists(obj2) and obj1 != obj2:

            # parent children
            jointGroup = cmds.createNode('transform')
            children   = cmds.listRelatives( obj2, type='transform' )
            if children:
                cmds.parent( set(children), jointGroup )

            # get position and rotation
            pos = cmds.xform( obj1, q=True, rp=True, ws=True )
            ori = cmds.xform( obj1, q=True, ro=True, ws=True )

            # set rotation orientation
            cmds.xform( obj2, ws = True, t = ( pos[0]*posVector[0], pos[1]*posVector[1], pos[2]*posVector[2] ), ro=ori )
            cmds.xform( obj2, ws = True, r = True, ro = oriVector )

            # set prefered angle
            if cmds.objExists( '%s.%s' % (obj1, 'preferredAngle') ):
                prefAngle = cmds.getAttr( '%s.%s' % (obj1, 'preferredAngle') )[0]
                if cmds.objExists( '%s.%s' % (obj2, 'preferredAngle') ):
                    cmds.setAttr( '%s.%s' % (obj2, 'preferredAngle'),
                                  prefAngle[0],
                                  prefAngle[1],
                                  prefAngle[2] )

            # re-parent
            if children:
                cmds.parent( children, obj2 )
            cmds.delete( jointGroup )

        else:
            raise RuntimeError, 'Node not found: %s' % obj2

    # --------------------------------------------------------------------------
    # re-select objects
    if selection:
        cmds.select( selection )
    else:
        cmds.select( cl= True)
示例#12
0
文件: curve.py 项目: jonntd/japeto
 def cvs(self, value):
     cvList = common.toList(value)
     self.__cvs = cvList