def on_reference( self, theFile ): api.referenceFile( theFile, 'ref' )
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 = filesystem.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 = filesystem.Path( scene ) curScene = filesystem.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: scene.editoradd() cmd.file( f=True, save=True ) cmd.file( f=True, new=True ) api.referenceFile( scene, 'model' ) #rename the scene to the rig rigSceneName = namingHelpers.stripKnownAssetSuffixes( scene.name() ) rigSceneName = '%s_rig.ma' % rigSceneName rigScene = scene.up() / rigSceneName cmd.file( rename=rigScene ) rigScene.editoradd() cmd.file( f=True, save=True, typ='mayaAscii' ) else: rigScene = scene buildRigForAllParts() setupMirroring() return rigScene