예제 #1
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