Ejemplo n.º 1
0
def setWritable( fileName ):
    fileName = Path( fileName )

    writable = True

    if fileName.exists() and fileName.isfile():
        if not fileName.access( os.W_OK ):
            writable = False

    return writable
Ejemplo n.º 2
0
def TransformExport_Import(imp=1):
    if imp:
        sel = mc.ls(sl=1, type='transform')
        if sel:
            for obj in sel:
                sceneName = mc.file(q=True, l=True)
                #print sceneName
                if sceneName:
                    fileName, extName = os.path.splitext(sceneName[0])
                    jsonFile = '%s_%s.json' % (fileName, obj)

                    startF = mc.playbackOptions(q=1, min=1)
                    endF = mc.playbackOptions(q=1, max=1)

                    outDIC = {
                        "Name": obj,
                        "frameStart": startF,
                        "frameEnd": endF,
                        "frames": {
                            "matrix_world": {}
                        }
                    }
                    for x in range(int(startF), int(endF) + 1):
                        mc.currentTime(x)
                        outDIC["frames"]["matrix_world"][str(x)] = mc.xform(
                            obj, q=1, matrix=1, ws=1)

                    outFile = open(jsonFile, 'w')
                    json.dump(outDIC, outFile, indent=2)
                    outFile.close()

    else:
        sceneName = mc.file(q=True, l=True)
        fileName, extname = os.path.splitext(sceneName[0])
        jsonFile = Path('%s/' % (fileName.rsplit('/', 1)[0]))
        poseJsons = [p for p in jsonFile.glob("*.json") if "001" in p]
        for jsonF in poseJsons:
            print jsonF
            poseData = json.load(open(jsonF))
            obj = poseData['Name']
            startF = poseData['frameStart']
            endF = poseData['frameEnd']
            print poseData
            mc.playbackOptions(min=int(startF), max=int(endF))

            if mc.ls(obj, type='transform'):
                for c, vals in poseData["frames"]["matrix_world"].iteritems():
                    mc.currentTime(int(c))
                    mc.xform(obj, matrix=vals)
                    for x in [
                            'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy',
                            'sz'
                    ]:
                        mc.setKeyframe('%s.%s' % (obj, x))
Ejemplo n.º 3
0
def openFromClipboard():

    filepath = Path(QtGui.QClipboard().text().strip())

    if filepath.exists():
        if filepath.ext.lower() == '.mb':
            fileType = 'mayaBinary'
        if filepath.ext.lower() == '.ma':
            fileType = 'mayaAscii'

        mel.addRecentFile(filepath.cannonicalPath(), fileType)

        openFile(filename, f=True)
Ejemplo n.º 4
0
def checkSave( fileName=None ):

    if fileName is None:
        fileName = pm.sceneName()
    else:
        fileName = Path( fileName )
        mc.file( rename=fileName )

    if not setWritable( fileName ):
        mel.warning( 'File "%s" is read-only. Could not save.' % fileName.basename() )

        return False


    mc.file( save=True )
    print '// Result: %s //' % fileName

    return True
Ejemplo n.º 5
0
def _renderCleanup( path, filename ):

    pm.window( 'glRenderWindow', e=1, vis=0 )

    f1 = filename.replace('@', str(int(pm.currentTime())) )

    f2 = filename.replace('@.', '' )

    p1 = Path(path) / f1
    p2 = Path(path) / f2

    if not p2.exists():
        p1.rename( p2 )
    else:
        print 'File exists:', p2

    #os.rename


    '''
Ejemplo n.º 6
0
    def _import( self, *args ):

        path = pm.fileDialog2( dialogStyle=2,
                               fileMode=1,
                               caption='Choose Pose File',
                               okCaption='Import',
                               selectFileFilter='Poses',
                               fileFilter='Poses (*.pose *.group)'
                               )

        if path is None:
            return
        else:
            path = path[0]

        path = Path(path)
        if path.isfile():
            data = ''.join(file( path ).read().splitlines())

            if len( data ) is not 0:
                data = eval( data )

                name = path.namebase
                ext = path.ext[1:]

                if ext == 'group':
                    print 'Group: "%s"' % name
                    if self._poseGroups.has_key( name ):

                        result = pm.confirmDialog( title='Import Group',
                                                message='Group "%s" already exists. Overwrite existing poses?' % name,
                                                button=['Overwrite', 'Cancel'],
                                                defaultButton='Overwrite',
                                                cancelButton='Cancel',
                                                dismissString='Cancel' )
                        if result == 'Overwrite':
                            self._poseGroups[ name ].update( data )
                    else:
                        self._poseGroups[ name ] = data

                    self._updateGroupList()
                    #setSelect for optionMenu broken with pymel 0.6+
                    OptionMenu( self.groupOM, edit=True, select=self._sortedGroupList().index( name ) + 1 )
                    self._updatePoseList()

                elif ext == 'pose':
                    print 'Pose: "%s"' % name

                    currentGroup = self._poseGroups[ self.groupOM.getValueStr() ]
                    if currentGroup.has_key( name ):
                        result = pm.confirmDialog( title='Import Pose',
                                                message='Overwrite existing pose "%s"?' % name,
                                                button=['Overwrite', 'Cancel'],
                                                defaultButton='Overwrite',
                                                cancelButton='Cancel',
                                                dismissString='Cancel' )
                        if result == 'Overwrite':
                            currentGroup[ name ] = data
                    else:
                        currentGroup[ name ] = data

                    self._updatePoseList()
                    self.poseListTSL.setSelectItem( name )

                self._savePrefs()