def build_popup(self, parent, *a): cmd.setParent(parent, m=True) cmd.menu(parent, e=True, dai=True) thisFile = Path(cmd.file(q=True, sn=True)) #if the file doesn't exist, then use teh cwd if not thisFile.exists(): thisFile = thisFile.getcwd() / "tmp.ma" dir = thisFile.up() curFile = Path(cmd.textField(self.UI_file, q=True, tx=True)) for f in dir.files(): if f.hasExtension(skinWeights.EXTENSION): cmd.menuItem(l=f.name(), cb=f == curFile, c=Callback(cmd.textField, self.UI_file, e=True, tx=f)) cmd.menuItem(d=True) cmd.menuItem(l="browse", c=self.on_browseWeightFile) cmd.menuItem(d=True) cmd.menuItem(l="clear", c=lambda *a: cmd.textField(self.UI_file, e=True, tx='')) if curFile.exists(): cmd.menuItem(d=True) addExploreToMenuItems(curFile)
def getControlShapeFiles(): dir = CONTROL_DIRECTORY if isinstance(dir, basestring): dir = Path(dir) if not isinstance(dir, Path) or not dir.exists(): dir = Path(__file__).up() shapes = [] if dir.exists(): shapes = [f for f in dir.files() if f.hasExtension('shape')] if not shapes: searchPaths = map(Path, sys.path) searchPaths += map(Path, os.environ.get('MAYA_SCRIPT_PATH', '').split(';')) searchPaths = removeDupes(searchPaths) for d in searchPaths: try: shapes += [f for f in d.files() if f.hasExtension('shape')] except WindowsError: continue return shapes
def getControlShapeFiles(): dir = CONTROL_DIRECTORY if isinstance( dir, basestring ): dir = Path( dir ) if not isinstance( dir, Path ) or not dir.exists(): dir = Path( __file__ ).up() shapes = [] if dir.exists(): shapes = [ f for f in dir.files() if f.hasExtension( 'shape' ) ] if not shapes: searchPaths = map( Path, sys.path ) searchPaths += map( Path, os.environ.get( 'MAYA_SCRIPT_PATH', '' ).split( ';' ) ) searchPaths = removeDupes( searchPaths ) for d in searchPaths: try: shapes += [ f for f in d.files() if f.hasExtension( 'shape' ) ] except WindowsError: continue return shapes
def addExploreToMenuItems( filepath ): if filepath is None: return filepath = Path( filepath ) if not filepath.exists(): filepath = filepath.getClosestExisting() if filepath is None: return cmd.menuItem(l="Explore to location...", c=lambda x: mel.zooExploreTo( filepath ), ann='open an explorer window to the location of this file/directory') cmd.menuItem(l="CMD prompt to location...", c=lambda x: mel.zooCmdTo( filepath ), ann='open a command prompt to the location of this directory')
def on_browse(self, *a): curValue = self.getValue() ext = curValue.getExtension() or 'txt' if curValue.isFile(): curValue = curValue.up() elif not curValue.isDir(): curValue = Path(cmd.file(q=True, sn=True)).up(2) if not curValue.exists(): curValue = Path('') filepath = cmd.fileDialog(directoryMask=curValue / ("/*.%s" % ext)) if filepath: self.setValue(filepath, True)
def build_popup( self, parent, *a ): cmd.setParent( parent, m=True ) cmd.menu( parent, e=True, dai=True ) thisFile = Path( cmd.file( q=True, sn=True ) ) #if the file doesn't exist, then use teh cwd if not thisFile.exists(): thisFile = thisFile.getcwd() / "tmp.ma" dir = thisFile.up() curFile = Path( cmd.textField( self.UI_file, q=True, tx=True ) ) for f in dir.files(): if f.hasExtension( skinWeights.EXTENSION ): cmd.menuItem( l=f.name(), cb=f==curFile, c=Callback( cmd.textField, self.UI_file, e=True, tx=f ) ) cmd.menuItem( d=True ) cmd.menuItem( l="browse", c=self.on_browseWeightFile ) cmd.menuItem( d=True ) cmd.menuItem( l="clear", c=lambda *a: cmd.textField( self.UI_file, e=True, tx='' ) ) if curFile.exists(): cmd.menuItem( d=True ) addExploreToMenuItems( curFile )
def on_browse(self, *a): curValue = self.getValue() ext = curValue.getExtension() or "txt" if curValue.isFile(): curValue = curValue.up() elif not curValue.isDir(): curValue = Path(cmd.file(q=True, sn=True)).up(2) if not curValue.exists(): curValue = Path("") filepath = cmd.fileDialog(directoryMask=curValue / ("/*.%s" % ext)) if filepath: self.setValue(filepath, True)
def buildRigForModel( scene=None, referenceModel=True, deletePlacers=False ): ''' given a model scene whose skeleton is assumed to have been built by the skeletonBuilder tool, this function will create a rig scene by referencing in said model, creating the rig as best it knows how, saving the scene in the appropriate spot etc... ''' #if no scene was passed, assume we're acting on the current scene if scene is None: scene = Path( cmd.file( q=True, sn=True ) ) #if the scene WAS passed in, open the desired scene if it isn't already open else: scene = Path( scene ) curScene = Path( cmd.file( q=True, sn=True ) ) if curScene: if scene != curScene: mel.saveChanges( 'file -f -open "%s"' % scene ) else: cmd.file( scene, f=True, open=True ) #if the scene is still none bail... if not scene and referenceModel: raise SceneNotSavedError( "Uh oh, your scene hasn't been saved - Please save it somewhere on disk so I know where to put the rig. Thanks!" ) #backup the current state of the scene, just in case something goes south... if scene.exists(): backupFilename = scene.up() / ('%s_backup.%s' % (scene.name(), scene.getExtension())) if backupFilename.exists(): backupFilename.delete() cmd.file( rename=backupFilename ) cmd.file( save=True, force=True ) cmd.file( rename=scene ) #finalize failedParts = finalizeAllParts() if failedParts: confirmDialog( t='Finalization Failure', m='The following parts failed to finalize properly:\n\n%s' % '\n'.join( map( str, failedParts ) ), b='OK', db='OK' ) return #delete placers if desired - NOTE: this should be done after after finalization because placers are often used to define alignment for end joints if deletePlacers: for part in SkeletonPart.IterAllParts(): placers = part.getPlacers() if placers: delete( placers ) #if desired, create a new scene and reference in the model if referenceModel: #remove any unknown nodes in the scene - these cause maya to barf when trying to save unknownNodes = ls( type='unknown' ) if unknownNodes: delete( unknownNodes ) #scene.editoradd() cmd.file( f=True, save=True ) cmd.file( f=True, new=True ) referenceFile( scene, 'model' ) #rename the scene to the rig rigSceneName = '%s_rig.ma' % scene.name() rigScene = scene.up() / rigSceneName cmd.file( rename=rigScene ) cmd.file( f=True, save=True, typ='mayaAscii' ) else: rigScene = scene buildRigForAllParts() setupMirroring() return rigScene