MFileIO Class Reference

#include <MFileIO.h>

Class Description

I/O operations on scene files.

Methods for opening, saving, importing, exporting and referencing files.

The MFileIO class provides a set of global functions that can be used to load and store scene elements into maya files. Methods are also provided to import elements from other files into the current scene, and export elements of the current scene into files. As well, references to other files can be created and removed.

This class implements only the most common operations from the full set possible with the MEL command "file." See the documentation of this command for a complete listing of all the possiblities. If more control is required than provided by this class, a MEL command can be constructed according to the instructions for the "file" command, and issued via the executeCommand method of the MGlobal class.

+ Examples:

Public Types

enum  ReferenceMode { kLoadDefault, kLoadAllReferences, kLoadNoReferences }
 Specifies which references to load. More...
 
enum  MayaFileFormatVersion
 Specifies the unique identifier for official Maya file format versions.
 
enum  NamespaceMergeMethod { kRemoveNamespaceIfEmpty, kMergeNamespaceWithRootNamespace, kMergeNamespaceWithParentNamespace, kForceDeleteNamespaceContent }
 Specifies what to do with objects remaining in the file reference's namespace, when the file reference is removed. More...
 
enum  ExportType {
  kExportTypeAll, kExportTypeSelected, kExportTypeAnim, kExportTypeAnimFromReference,
  kExportTypeAsReference, kExportTypeEdits, kExportTypePrefObjects
}
 Types of export operation. More...
 

Public Member Functions

 MFileIO ()
 Default class constructor.
 
 MFileIO (const MString &fileName)
 Class constructor that sets the current active scene. More...
 
virtual ~MFileIO ()
 The class destructor.
 

Static Public Member Functions

static MString currentFile ()
 Return the name of the currently active scene. More...
 
static MStatus setCurrentFile (const MString &fileName)
 Set the name of the current active scene. More...
 
static MString fileType ()
 Return the type of the current active scene. More...
 
static MStatus getFileTypes (MStringArray &types)
 Returns an array of all the valid type names that Maya currently supports. More...
 
static MStatus newFile (bool force=false)
 Set everything back to a new file state. More...
 
static MStatus open (const MString &fileName, const char *type=NULL, bool force=false, ReferenceMode refMode=kLoadDefault, bool ignoreVersion=false)
 Open the given file, and set the current active scene to this file. More...
 
static MStatus save (bool force=false)
 Save the contents of the current scene. More...
 
static MStatus saveAs (const MString &fileName, const char *type=NULL, bool force=false)
 Save the contents of the current scene to the given file. More...
 
static MStatus importFile (const MString &fileName, const char *type=NULL, bool preserveReferences=false, const char *nameSpace=NULL, bool ignoreVersion=false)
 Import the scene elements from the given file into the current scene. More...
 
static MStatus exportSelected (const MString &fileName, const char *type=NULL, bool preserveReferences=false)
 Export all currently selected scene elements to the given file. More...
 
static MStatus exportAll (const MString &fileName, const char *type=NULL, bool preserveReferences=false)
 Export the current scene to the given file. More...
 
static MStatus exportAnimFromReference (const MString &fileName, const char *type=NULL)
 Export the animation from reference, to the specified file. More...
 
static MStatus exportAnimFromReference (const MString &fileName, const MString &refNodeName, const char *type=NULL)
 Export the animation from the specified reference node, to the specified file. More...
 
static MStatus exportSelectedAnimFromReference (const MString &fileName, const char *type=NULL)
 Export the selected animation from reference, to the specified file. More...
 
static MStatus exportSelectedAnimFromReference (const MString &fileName, const MString &refNodeName, const char *type=NULL)
 Export the selected animation from reference, to the specified file. More...
 
static MStatus exportAnim (const MString &fileName, const char *type=NULL)
 Export animation to the specified file. More...
 
static MStatus exportSelectedAnim (const MString &fileName, const char *type=NULL)
 Export selected animation to the specified file. More...
 
static MStatus exportAsReference (const MString &fileName, const char *type=NULL)
 Export the selected objects into a reference file. More...
 
static MStatus getReferences (MStringArray &references, bool wantUnresolvedNames=false)
 Return an array of all the files referenced from the currently active scene. More...
 
static MStatus getFiles (MStringArray &files, bool wantUnresolvedNames=false, bool wantReferencesOnly=false)
 Return an array of all the files used by the currently active scene. More...
 
static MStatus getReferenceNodes (const MString &fileName, MStringArray &nodes)
 Return an array of all the nodes referenced by the given filename. More...
 
static MStatus getReferenceNodes (const MString &fileName, MSelectionList &list)
 Return an array of all the nodes referenced by the given filename. More...
 
static MStatus getReferenceConnectionsMade (const MString &fileName, MStringArray &connections)
 Return an array of attribute pairs representing connections made to nodes in the given referenced file. More...
 
static MStatus getReferenceConnectionsBroken (const MString &fileName, MStringArray &connections)
 Return an array of attribute pairs representing connections broken to nodes in the given referenced file. More...
 
static MStatus getReferenceConnectionsBroken (const MString &fileName, MPlugArray &srcPlugs, MPlugArray &destPlugs)
 Returns the source and destination plugs corresponding to all the connections broken between nodes in the given referenced file. More...
 
static MStatus getReferenceConnectionsBroken (const MObject &node, MStringArray &connections, bool append=false, bool removeDuplicates=true)
 Returns an array of plug name pairs corresponding to the broken connections from referenced files, where those connections involved the specified node. More...
 
static MStatus getReferenceConnectionsBroken (const MObject &node, MPlugArray &srcPlugs, MPlugArray &destPlugs, bool append=false, bool removeDuplicates=true)
 Returns arrays of source and destination plugs corresponding to the broken connections from referenced files, where those connections involved the specified node. More...
 
static MStatus reference (const MString &fileName, bool deferReference=false, bool lockReference=false, const MString &nameSpace="")
 Add the given filename as a reference from the current file. More...
 
static MStatus removeReference (const MString &fileName, NamespaceMergeMethod namespaceMergeMethod=kRemoveNamespaceIfEmpty)
 Remove the named file as a reference from the current file. More...
 
static bool isReadingFile ()
 Determine if Maya is currently in the middle of a file read operation. More...
 
static bool isWritingFile ()
 Determine if Maya is currently in the middle of a file write operation. More...
 
static bool isOpeningFile ()
 Determine if Maya is currently performing a file open operation. More...
 
static bool isNewingFile ()
 Determine if Maya is currently performing a "new" operation. More...
 
static bool isSavingReference ()
 Determine if Maya is currently in the middle of a save reference operation. More...
 
static bool mustRenameToSave (MStatus *ReturnStatus=NULL)
 Scenes may be flagged as needing to be renamed before saving. More...
 
static MStatus setMustRenameToSave (bool)
 This method enabled or disables a state where the current Maya scene must save to a different file name. More...
 
static MString mustRenameToSaveMsg (MStatus *ReturnStatus=NULL)
 This method returns a string that is displayed when a user attempts to save a scene that was set to not overwrite itself. More...
 
static MStatus setMustRenameToSaveMsg (const MString &)
 This method sets a string that is displayed when a user attempts to save a scene that was set to not overwrite itself. More...
 
static MString beforeOpenFilename (MStatus *ReturnStatus=NULL)
 Retrieves the name of the file requested to be opened. More...
 
static MString beforeImportFilename (MStatus *ReturnStatus=NULL)
 Retrieves the name of the file requested to be imported. More...
 
static MString beforeSaveFilename (MStatus *ReturnStatus=NULL)
 Retrieves the name of the file requested to be saved. More...
 
static MString beforeExportFilename (MStatus *ReturnStatus=NULL)
 Retrieves the name of the file requested to be exported. More...
 
static MString beforeReferenceFilename (MStatus *ReturnStatus=NULL)
 Retrieves the name of the file requested to be referenced. More...
 
static MPxFileTranslatorbeforeOpenUserFileTranslator (MStatus *ReturnStatus=NULL)
 Retrieves the plug-in-defined file translator being used for file open, if any. More...
 
static MPxFileTranslatorbeforeImportUserFileTranslator (MStatus *ReturnStatus=NULL)
 Retrieves the plug-in-defined file translator being used for import, if any. More...
 
static MPxFileTranslatorbeforeSaveUserFileTranslator (MStatus *ReturnStatus=NULL)
 Retrieves the plug-in-defined file translator being used for file save, if any. More...
 
static MPxFileTranslatorbeforeExportUserFileTranslator (MStatus *ReturnStatus=NULL)
 Retrieves the plug-in-defined file translator being used for export, if any. More...
 
static MPxFileTranslatorbeforeReferenceUserFileTranslator (MStatus *ReturnStatus=NULL)
 Retrieves the plug-in-defined file translator being used for file reference, if any. More...
 
static ExportType exportType (MStatus *ReturnStatus=NULL)
 Returns the type of export currently in progress. More...
 
static MString getLastTempFile (MStatus *ReturnStatus=NULL)
 Returns the temp file used during file save. More...
 
static bool getErrorStatus (MStatus *ReturnStatus=NULL)
 Returns the error status of the last file read. More...
 
static MStatus resetError ()
 Resets the error. More...
 
static MStatus setError ()
 Sets the internal errorIO flag. More...
 
static MString loadReference (const MString &referenceFileName, MStatus *returnStatus=NULL)
 Loads the reference, referenced by the given reference node name and file name. More...
 
static MString loadReferenceByNode (const MString &referenceNodeName, MStatus *returnStatus=NULL)
 Loads the reference, referenced by the given reference node name. More...
 
static MString loadReferenceByNode (MObject &referenceNode, MStatus *returnStatus=NULL)
 Loads the reference, referenced by the given reference node object. More...
 
static MString unloadReference (const MString &referenceFileName, MStatus *returnStatus=NULL)
 Unloads the reference, referenced by the given reference node and file. More...
 
static MString unloadReferenceByNode (const MString &referenceNodeName, MStatus *returnStatus=NULL)
 Unloads the reference, referenced by the given reference node. More...
 
static MString unloadReferenceByNode (MObject &referenceNode, MStatus *returnStatus=NULL)
 Unloads the reference, referenced by the given reference node. More...
 
static MString getReferenceFileByNode (MObject &referenceNode, MStatus *returnStatus=NULL)
 Returns the name of the reference file, which contains the given reference node. More...
 
static MStatus cleanReference (const MString &referenceNodeName, const char *editCommand=NULL, MStatus *returnStatus=NULL)
 This function removes the edits from the passed in reference node. More...
 
static MStatus saveReference (const MString &referenceNodeName, MStatus *returnStatus=NULL)
 This function saves reference node edits and connections to reference file. More...
 
static MString fileCurrentlyLoading ()
 Return the name of the file currently being loaded. More...
 
static bool isImportingFile ()
 Determine if Maya is currently in the middle of a file import operation. More...
 
static bool isReferencingFile ()
 Determine if Maya is currently in the middle of a file reference operation. More...
 
static int currentlyReadingFileVersion ()
 Each Maya file format version has a unique integer identifier. More...
 
static int latestMayaFileVersion ()
 Each Maya file format version has a unique integer identifier. More...
 
static const char * className ()
 Returns the name of this class. More...
 
static MStatus import (const MString &fileName, const char *type=NULL, bool preserveReferences=false, const char *nameSpace=NULL)
 This method is obsolete. This method is not available in Python. More...
 
static const adsk::Data::Associationsmetadata (MStatus *ReturnStatus=NULL)
 This method is not available in Python. More...
 
static MStatus setMetadata (const adsk::Data::Associations &)
 This method is not available in Python. More...
 
static MStatus deleteMetadata ()
 This method is not available in Python. More...
 

Member Enumeration Documentation

Specifies which references to load.

Enumerator
kLoadDefault 

Load references that were loaded when scene was saved.

kLoadAllReferences 

Load all references in the scene.

kLoadNoReferences 

Don't load any references.

Specifies what to do with objects remaining in the file reference's namespace, when the file reference is removed.

Enumerator
kRemoveNamespaceIfEmpty 

If the reference is alone in its namespace, remove the namespace.

Else, keep the objects and the namespace.

kMergeNamespaceWithRootNamespace 

Move remaining objects to root namespace, and delete namespace.

Cannot be used if the reference resides in the root namespace.

kMergeNamespaceWithParentNamespace 

Move remaining objects to parent namespace, and delete namespace.

Cannot be used if the reference resides in the root namespace.

kForceDeleteNamespaceContent 

Delete all namespace content, and delete namespace.

Cannot be used if the reference resides in the root namespace.

enum ExportType

Types of export operation.

Enumerator
kExportTypeAll 

Export all.

kExportTypeSelected 

Export selected.

kExportTypeAnim 

Export anim.

kExportTypeAnimFromReference 

Export anim from reference.

kExportTypeAsReference 

Export as reference.

kExportTypeEdits 

Export edits.

kExportTypePrefObjects 

Export pref objects.

Constructor & Destructor Documentation

MFileIO ( const MString fileName)

Class constructor that sets the current active scene.

Parameters
[in]fileNamename of the new active scene

Member Function Documentation

MString currentFile ( )
static

Return the name of the currently active scene.

Returns
An MString containing the file name
+ Examples:
MStatus setCurrentFile ( const MString fileName)
static

Set the name of the current active scene.

Parameters
[in]fileNamethe name of the new active scene.
Returns
MString fileType ( )
static

Return the type of the current active scene.

Returns
MStatus getFileTypes ( MStringArray types)
static

Returns an array of all the valid type names that Maya currently supports.

Only elements from this list are valid arguments for the type arguments to open, saveAs, import, exportSelected, and exportAll.

It should be noted that the results of this function will change as file translators that are implemented as plugins are loaded or unloaded.

The file types mayaAscii and mayaBinary will always be available.

Parameters
[out]typesa reference to an MStringArray which on return contains the list of supported file types.
Returns
MStatus newFile ( bool  force = false)
static

Set everything back to a new file state.

Parameters
[in]forcesucceed even if there are unsaved changes
Returns
+ Examples:
MStatus open ( const MString fileName,
const char *  type = NULL,
bool  force = false,
ReferenceMode  refMode = kLoadDefault,
bool  ignoreVersion = false 
)
static

Open the given file, and set the current active scene to this file.

If there are unsaved changes in the current scene, this operation will fail unless the force flag is set to true.

Parameters
[in]fileNamename of the file to open
[in]typeif NULL, Maya will try to deduce the type of the file. if not NULL, it contains a file type to use when opening the file.
[in]forcesucceed even if there are unsaved changes
[in]refModespecify whether to load all references, no references, or the references that were loaded when the scene was saved.
[in]ignoreVersionif true, then Maya will ignore the version number when opening the file
Returns
MStatus save ( bool  force = false)
static

Save the contents of the current scene.

If there have been no changes to the scene since the last save, then this operation will succeed, but not actually rewrite the save file unless the force flag is set to true.

Parameters
[in]forcesucceed even if there have been no changes
Returns
MStatus saveAs ( const MString fileName,
const char *  type = NULL,
bool  force = false 
)
static

Save the contents of the current scene to the given file.

If there have been no changes to the scene since the last save, then this operation will succeed, but not actually rewrite the save file unless the force flag is set to true.

Parameters
[in]fileNamename of the file to write to
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
[in]forcesucceed even if there have been no changes since the last save operation
Returns
MStatus importFile ( const MString fileName,
const char *  type = NULL,
bool  preserveReferences = false,
const char *  nameSpace = NULL,
bool  ignoreVersion = false 
)
static

Import the scene elements from the given file into the current scene.

This operation is similar to open, but instead of replacing the current scene with the one from the new file, it adds the elements from that file to the existing ones in the current scene.

Parameters
[in]fileNamename of the file from which to import objects
[in]typeif NULL, Maya will try to deduce the type of the file. If not NULL, it must contain a file type to use when importing the file.
[in]preserveReferencesBoolean to indicate whether the references need to be preserved.
[in]nameSpaceoptional name of the namespace to use when importing objects. Use NULL for default of no namespace.
[in]ignoreVersionBoolean to control whether to ignore version when importing a file.
Returns
MStatus exportSelected ( const MString fileName,
const char *  type = NULL,
bool  preserveReferences = false 
)
static

Export all currently selected scene elements to the given file.

Parameters
[in]fileNamename of the file to which to export the objects
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
[in]preserveReferencesBoolean to indicate whether the references need to be preserved.
Returns
MStatus exportAll ( const MString fileName,
const char *  type = NULL,
bool  preserveReferences = false 
)
static

Export the current scene to the given file.

Parameters
[in]fileNamename of the file to which to export the objects
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
[in]preserveReferencesBoolean to indicate whether the references need to be preserved.
Returns
MStatus exportAnimFromReference ( const MString fileName,
const char *  type = NULL 
)
static

Export the animation from reference, to the specified file.

Parameters
[in]fileNamename of the file to which the animation will be exported.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus exportAnimFromReference ( const MString fileName,
const MString refNodeName,
const char *  type = NULL 
)
static

Export the animation from the specified reference node, to the specified file.

Parameters
[in]fileNamename of the file to which the animation will be exported.
[in]refNodeNamename of the reference whose animation will be exported.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus exportSelectedAnimFromReference ( const MString fileName,
const char *  type = NULL 
)
static

Export the selected animation from reference, to the specified file.

Parameters
[in]fileNamename of the file to which the animation will be exported.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus exportSelectedAnimFromReference ( const MString fileName,
const MString refNodeName,
const char *  type = NULL 
)
static

Export the selected animation from reference, to the specified file.

Parameters
[in]fileNamename of the file to which the animation will be exported.
[in]refNodeNamename of the reference whose animation will be exported.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus exportAnim ( const MString fileName,
const char *  type = NULL 
)
static

Export animation to the specified file.

Parameters
[in]fileNamename of the file to which the animation will be exported.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus exportSelectedAnim ( const MString fileName,
const char *  type = NULL 
)
static

Export selected animation to the specified file.

Parameters
[in]fileNamename of the file to which the animation will be exported.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus exportAsReference ( const MString fileName,
const char *  type = NULL 
)
static

Export the selected objects into a reference file.

Parameters
[in]fileNamename of the file to which the selected objects will be exported as reference.
[in]typeif NULL, Maya will write the file in mayaAscii format. if not NULL, it contains a file type to use when writing the file.
Returns
MStatus getReferences ( MStringArray references,
bool  wantUnresolvedNames = false 
)
static

Return an array of all the files referenced from the currently active scene.

Parameters
[out]referencesa reference to an MStringArray which on return contains the list of referenced files.
[in]wantUnresolvedNamesspecify if unresolved file names should be returned. Default is false.
Returns
+ Examples:
MStatus getFiles ( MStringArray files,
bool  wantUnresolvedNames = false,
bool  wantReferencesOnly = false 
)
static

Return an array of all the files used by the currently active scene.

Includes file references, file textures, cache files, image planes etc.

Parameters
[out]filesa reference to an MStringArray which on return contains the list of referenced files.
[in]wantUnresolvedNamesspecify if unresolved file names should be returned. Default is false.
[in]wantReferencesOnlyspecify if only file references should be returned. Setting this to true makes this function equivalent to MFileIO::getReferences(). Default is false.
Returns
MStatus getReferenceNodes ( const MString fileName,
MStringArray nodes 
)
static

Return an array of all the nodes referenced by the given filename.

Parameters
[in]fileNamean MString which contains the name of the referenced file.
[out]nodesa reference to an MStringArray which on return contains the list of nodes in the referenced file.
Returns
+ Examples:
MStatus getReferenceNodes ( const MString fileName,
MSelectionList list 
)
static

Return an array of all the nodes referenced by the given filename.

Parameters
[in]fileNamean MString which contains the name of the referenced file.
[out]lista reference to an MSelectionList which on return contains the list of nodes in the referenced file.
Returns
  • MS::kSuccess operation successful
  • MS::kFailure operation failed due to multiple reference files with the same short name.
  • MS::kFailure operation failed due to no reference files matching the fileName argument.
  • MS::kFailure operation failed
MStatus getReferenceConnectionsMade ( const MString fileName,
MStringArray connections 
)
static

Return an array of attribute pairs representing connections made to nodes in the given referenced file.

The first element of the pair is the source attribute in the connection, and the second is the destination. These pairs correspond to the "connectAttr" statements in a scene file where changes to the referenced file occur after the referenced file has been opened.

Parameters
[in]fileNamean MString which contains the name of the referenced file.
[out]connectionsa reference to an MStringArray which on return contains the source/destination connection pairs.
Returns
+ Examples:
MStatus getReferenceConnectionsBroken ( const MString fileName,
MStringArray connections 
)
static

Return an array of attribute pairs representing connections broken to nodes in the given referenced file.

The first element of the pair is the source attribute in the connection, and the second is the destination. These pairs correspond to the "disconnectAttr" statements in a scene file where changes to the referenced file occur after the referenced file has been opened.

Parameters
[in]fileNamean MString which contains the name of the referenced file.
[out]connectionsa reference to an MStringArray which on return contains the source/destination connection pairs.
Returns
+ Examples:
MStatus getReferenceConnectionsBroken ( const MString fileName,
MPlugArray srcPlugs,
MPlugArray destPlugs 
)
static

Returns the source and destination plugs corresponding to all the connections broken between nodes in the given referenced file.

These pairs correspond to the "disconnectAttr" statements in a scene file where changes to the referenced file occur after the referenced file has been opened.

Parameters
[in]fileNamean MString which contains the name of the referenced file.
[out]srcPlugsan MPlugArray which will receive the source plugs of each broken connection.
[out]destPlugsan MPlugArray which contains the destination plugs of each broken connection.
Returns
MStatus getReferenceConnectionsBroken ( const MObject node,
MStringArray connections,
bool  append = false,
bool  removeDuplicates = true 
)
static

Returns an array of plug name pairs corresponding to the broken connections from referenced files, where those connections involved the specified node.

To put it another way, if a referenced file contained a connection to the specified node when it was loaded, and that connection was later broken in the main scene, then the names of source and destination plugs for that connection will be returned.

The first element of the pair is the source plug in the connection, and the second is the destination. These pairs correspond to the "disconnectAttr" statements in a scene file where changes to the referenced file occur after the referenced file has been opened.

Parameters
[in]nodethe node whose broken reference connections will be returned.
[out]connectionsa reference to an MStringArray which on return contains the source/destination connection pairs.
[in]appendIf true, the connection strings will be appended to the existing contents of the connections array. Otherwise the array will be cleared before the strings are added.
[in]removeDuplicatesIf true then any connections which are already in the connections array will be ignored. Otherwise they will be added to the array again.
Returns
MStatus getReferenceConnectionsBroken ( const MObject node,
MPlugArray srcPlugs,
MPlugArray destPlugs,
bool  append = false,
bool  removeDuplicates = true 
)
static

Returns arrays of source and destination plugs corresponding to the broken connections from referenced files, where those connections involved the specified node.

To put it another way, if a referenced file contained a connection to the specified node when it was loaded, and that connection was later broken in the main scene, then the source and destination plugs for that connection will be returned.

Parameters
[in]nodethe node whose broken connections should be returned.
[out]srcPlugsan MPlugArray which will receive the source plugs of each broken connection.
[out]destPlugsan MPlugArray which will receive the destination plugs of each broken connection.
[in]appendif true, then srcPlugs and destPlugs will not be initially cleared, meaning that the plugs from any broken connections found will be appended after whatever is already in those arrays. This can be useful for building up an array of connections for several nodes.
[in]removeDuplicatesif the append parameter is true, then it is possible that some of the broken connections found for node will already exist in plug arrays. For example, if node A and node B have a broken reference connection between them, then they will both return that connection when passed to this method. Setting removeDuplicates true will cause these duplicate connections to only appear in the plug arrays once.
Returns
MStatus reference ( const MString fileName,
bool  deferReference = false,
bool  lockReference = false,
const MString nameSpace = "" 
)
static

Add the given filename as a reference from the current file.

When a new file is opened, the contents of any files it references are read into the scene, however maya remembers that the elements came from the referenced file, and does not write them during a save operation. Instead the reference is written so the contents of the referenced file (which might have changed) will be read again when the scene is reloaded.

Parameters
[in]fileNamename of the file to add as a reference.
[in]deferReferenceboolean to indicate whether loading has to be deferred.
[in]lockReferenceIf true, all nodes and attributes from the referenced file will be locked.
[in]nameSpacename space to add the contents of the referenced file to. If no namespace is provided, name-clashes will be resolved by prefixing with the filename.
Returns
MStatus removeReference ( const MString fileName,
NamespaceMergeMethod  namespaceMergeMethod = kRemoveNamespaceIfEmpty 
)
static

Remove the named file as a reference from the current file.

Parameters
[in]fileNamename of the file to remove as a reference
[in]namespaceMergeMethodwhat to do with objects remaining in the namespace after the file is removed: merge with parent namespace, merge with root namespace, delete all objects, or keep objects in the namespace (default). Merge with parent/root and delete all objects cannot be used if the reference resides in the root namespace.
Returns
bool isReadingFile ( )
static

Determine if Maya is currently in the middle of a file read operation.

File import operations and file reference operations are both also file read operations.

Returns
  • true if maya is currently in the process of reading a file
  • false if maya is not currently reading a file
+ Examples:
bool isWritingFile ( )
static

Determine if Maya is currently in the middle of a file write operation.

Returns
  • true if maya is currently in the process of writing a file
  • false if maya is not currently writing a file
bool isOpeningFile ( )
static

Determine if Maya is currently performing a file open operation.

This condition differs from isReadingFile() which is only true when were are actually reading the contents of the file from disk. In contrast, isOpeningFile() will be true during the pre-read operations such as the new operation to delete the current scene contents as well as post read-operations.

The isOpeningFile() method can be used in conjunction with isNewingFile() to determine if a "new" operation is currently being performed on behalf of an "open" operation.

Maya performs two types of "new" operations: 1) explicit "new" on account of a File>New or "file -new", and 2) implicit "new" due to file open. The isOpeningFile() method can be used in conjunction with isNewingFile() to determine if a "new" operation is currently being performed on behalf of an "open" operation. The following table lists how the isNewingFile() and isOpeningFile() methods can be used to determine the current state:

isNewingFile() returns false isNewingFile() returns true
isOpeningFile() returns false Maya is neither in new nor open Maya is perfroming an explicit new (a File>New or file -new)
isOpeningFile() returns true Maya is opening a file, and is not currently performing a new Maya is opening a file and is performing a new on behalf of the open

Based on the above table, it is easy to see how the four distinct states can easily be detected.

Returns
  • true if maya is currently in the process of opening a file
  • false if maya is not currently opening a file
+ Examples:
bool isNewingFile ( )
static

Determine if Maya is currently performing a "new" operation.

Maya performs two types of "new" operations: 1) explicit "new" on account of a File>New or "file -new", and 2) implicit "new" due to file open. The isOpeningFile() method can be used in conjunction with isNewingFile() to determine if a "new" operation is currently being performed on behalf of an "open" operation. The following table lists how the isNewingFile() and isOpeningFile() methods can be used to determine the current state:

isNewingFile() returns false isNewingFile() returns true
isOpeningFile() returns false Maya is neither in new nor open Maya is perfroming an explicit new (a File>New or file -new)
isOpeningFile() returns true Maya is opening a file, and is not currently performing a new Maya is opening a file and is performing a new on behalf of the open

Based on the above table, it is easy to see how the four distinct states can easily be detected.

Returns
  • true if maya is currently in the process of a new operation.
  • false if maya is not currently in new.
bool isSavingReference ( )
static

Determine if Maya is currently in the middle of a save reference operation.

i.e. When you do File > Save Reference Edits from the Reference Editor or `file -saveReference`.

Returns
  • true if Maya is currently in the process of a save reference operation
  • false if Maya is not currently doing a save reference
bool mustRenameToSave ( MStatus ReturnStatus = NULL)
static

Scenes may be flagged as needing to be renamed before saving.

The purpose is to prevent overwriting the original file, which may have had a significant change. Users will need to use save as to save the scene with a different file name.

This method returns true if the scene must be renamed before it can be saved.

Parameters
[out]ReturnStatusThe status.
Returns
true if this file must be renamed before saving.
Status Codes:
MStatus setMustRenameToSave ( bool  rename)
static

This method enabled or disables a state where the current Maya scene must save to a different file name.

This can be used to prevent a user from overwriting the original scene if a particularly dangerous or experimental change was made.

If enabled, the user must use save as to save the scene to a different name.

Once the file is renamed, this state is cleared and the file may be saved.

Parameters
[in]renametrue, if the scene should be saved to a different name.
Returns
MString mustRenameToSaveMsg ( MStatus ReturnStatus = NULL)
static

This method returns a string that is displayed when a user attempts to save a scene that was set to not overwrite itself.

See the MFileIO::setMustRenameToSave() documentation.

If a custom message was not set, this method will return an empty string.

Parameters
[out]ReturnStatusstatus
Returns
The error message to display.
Status Codes:
MStatus setMustRenameToSaveMsg ( const MString errorMsg)
static

This method sets a string that is displayed when a user attempts to save a scene that was set to not overwrite itself.

See the MFileIO::setMustRenameToSave() documentation.

To use the default error message, pass an empty string to this method.

Parameters
[in]errorMsgThe message to display when attempting a file save.
Returns
MString beforeOpenFilename ( MStatus ReturnStatus = NULL)
static

Retrieves the name of the file requested to be opened.

This name can be retrieved from within the beforeOpenCheck and beforeOpen callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be opened). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
The name of the file to be opened
Status Codes:
+ Examples:
MString beforeImportFilename ( MStatus ReturnStatus = NULL)
static

Retrieves the name of the file requested to be imported.

This name can be retrieved from within the beforeImportCheck and beforeImport callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be imported). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
The name of the file to be imported
Status Codes:
+ Examples:
MString beforeSaveFilename ( MStatus ReturnStatus = NULL)
static

Retrieves the name of the file requested to be saved.

This name can be retrieved from within the beforeSaveCheck and beforeSave callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be saved). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
The name of the file to be saved
Status Codes:
+ Examples:
MString beforeExportFilename ( MStatus ReturnStatus = NULL)
static

Retrieves the name of the file requested to be exported.

This name can be retrieved from within the beforeExportCheck and beforeExport callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be exported). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
The name of the file to be exported
Status Codes:
MString beforeReferenceFilename ( MStatus ReturnStatus = NULL)
static

Retrieves the name of the file requested to be referenced.

This name can be retrieved from within the beforeRefenceCheck and beforeRefence callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be referenced). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
The name of the file to be referenced
Status Codes:
+ Examples:
MPxFileTranslator * beforeOpenUserFileTranslator ( MStatus ReturnStatus = NULL)
static

Retrieves the plug-in-defined file translator being used for file open, if any.

If a standard Maya file translator (e.g. mayaAscii) is being used, returns NULL. The translator can be retrieved from within the beforeOpenCheck and beforeOpen callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be opened). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
A pointer to the file translator being used for file open, or NULL.
Status Codes:
MPxFileTranslator * beforeImportUserFileTranslator ( MStatus ReturnStatus = NULL)
static

Retrieves the plug-in-defined file translator being used for import, if any.

If a standard Maya file translator (e.g. mayaAscii) is being used, returns NULL. The translator can be retrieved from within the beforeImportCheck and beforeImport callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be imported). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
A pointer to the file translator being used to import, or NULL.
Status Codes:
MPxFileTranslator * beforeSaveUserFileTranslator ( MStatus ReturnStatus = NULL)
static

Retrieves the plug-in-defined file translator being used for file save, if any.

If a standard Maya file translator (e.g. mayaAscii) is being used, returns NULL. The translator can be retrieved from within the beforeSaveCheck and beforeSave callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be saved). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
A pointer to the file translator being used for file save, or NULL.
Status Codes:
MPxFileTranslator * beforeExportUserFileTranslator ( MStatus ReturnStatus = NULL)
static

Retrieves the plug-in-defined file translator being used for export, if any.

If a standard Maya file translator (e.g. mayaAscii) is being used, returns NULL. The translator can be retrieved from within the beforeExportCheck and beforeExport callback functions (that must be registered using MSceneMessage::addCallback() before the file is attempted to be exported). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
A pointer to the file translator being used to export, or NULL.
Status Codes:
MPxFileTranslator * beforeReferenceUserFileTranslator ( MStatus ReturnStatus = NULL)
static

Retrieves the plug-in-defined file translator being used for file reference, if any.

If a standard Maya file translator (e.g. mayaAscii) is being used, returns NULL. The translator can be retrieved from within the beforeRefenceCheck and beforeRefence callback functions. (that must be registered using MSceneMessage::addCallback() before the file is attempted to be referenced). If called outside of these two callback functions the results are undefined.

Parameters
[out]ReturnStatusStatus code
Returns
A pointer to the file translator being used for file reference, or NULL.
Status Codes:
MFileIO::ExportType exportType ( MStatus ReturnStatus = NULL)
static

Returns the type of export currently in progress.

The result is valid from the start of the kBeforeExportCheck callback through to the end of the kAfterExport callback, and for any callbacks which occur between them. See MSceneMessage for more information on these callbacks.

Parameters
[out]ReturnStatusStatus code
Returns
The type of export currently in progress.
Status Codes:
MString getLastTempFile ( MStatus ReturnStatus = NULL)
static

Returns the temp file used during file save.

Parameters
[out]ReturnStatusStatus code
Returns
The name of the temp file
Status Codes:
bool getErrorStatus ( MStatus ReturnStatus = NULL)
static

Returns the error status of the last file read.

Returns true if any error occurred during the last file read, else false is returned.

Parameters
[out]ReturnStatusStatus code
Returns
Boolean value indicating the error status.
Status Codes:
MStatus resetError ( )
static

Resets the error.

Returns
MStatus setError ( )
static

Sets the internal errorIO flag.

Setting this flag will trigger the display of the standard Maya file IO pop-up after a read or write operation. This method can be called during the MSceneMessage::kAfterFileRead callback.

Returns
MString loadReference ( const MString referenceFileName,
MStatus returnStatus = NULL 
)
static

Loads the reference, referenced by the given reference node name and file name.

Parameters
[in]referenceFileNameMString containing the name of the reference file.
[out]returnStatusStatus code
Returns
The name of the loaded reference file
MString loadReferenceByNode ( const MString referenceNodeName,
MStatus returnStatus = NULL 
)
static

Loads the reference, referenced by the given reference node name.

Parameters
[in]referenceNodeNameMString, name of the reference node.
[out]returnStatusStatus of the operation.
Returns
The name of the loaded reference file
MString loadReferenceByNode ( MObject referenceNode,
MStatus returnStatus = NULL 
)
static

Loads the reference, referenced by the given reference node object.

Parameters
[in]referenceNodeMObject of the reference node.
[out]returnStatusStatus of the operation.
Returns
The name of the loaded reference file
MString unloadReference ( const MString referenceFileName,
MStatus returnStatus = NULL 
)
static

Unloads the reference, referenced by the given reference node and file.

Parameters
[in]referenceFileNameMString containing the name of the reference file.
[out]returnStatusStatus of the operation.
Returns
The name of the unloaded reference file
MString unloadReferenceByNode ( const MString referenceNodeName,
MStatus returnStatus = NULL 
)
static

Unloads the reference, referenced by the given reference node.

Parameters
[in]referenceNodeNameMString containing the name of the reference node.
[out]returnStatusStatus of the operation.
Returns
The name of the unloaded reference file
MString unloadReferenceByNode ( MObject referenceNode,
MStatus returnStatus = NULL 
)
static

Unloads the reference, referenced by the given reference node.

Parameters
[in]referenceNodeMObject containing the reference node.
[out]returnStatusStatus of the operation.
Returns
The name of the unloaded reference file
MString getReferenceFileByNode ( MObject referenceNode,
MStatus returnStatus = NULL 
)
static

Returns the name of the reference file, which contains the given reference node.

Parameters
[in]referenceNodeMObject containing the reference node.
[out]returnStatusStatus of the operation.
Returns
The name of the reference file, containing the given node.
MStatus cleanReference ( const MString referenceNodeName,
const char *  editCommand = NULL,
MStatus returnStatus = NULL 
)
static

This function removes the edits from the passed in reference node.

The reference must be in an unloaded state.

Parameters
[in]referenceNodeNameName of the reference node.
[in]editCommandName of the edit command to be cleaned.
[out]returnStatusStatus of the operation.
Returns
MStatus saveReference ( const MString referenceFileName,
MStatus returnStatus = NULL 
)
static

This function saves reference node edits and connections to reference file.

Parameters
[in]referenceFileNameName of the reference file.
[out]returnStatusStatus of the operation.
Returns
MString fileCurrentlyLoading ( )
static

Return the name of the file currently being loaded.

Returns
An MString containing the name of the file being loaded. An empty string if no load is taking place.
+ Examples:
bool isImportingFile ( )
static

Determine if Maya is currently in the middle of a file import operation.

File import operations are a subset of file reading operations.

Returns
  • true if Maya is currently in the process of importing a file
  • false if Maya is not currently importing a file
bool isReferencingFile ( )
static

Determine if Maya is currently in the middle of a file reference operation.

File reference operations are a subset of file reading operations.

Returns
  • true if Maya is currently in the process of referencing a file
  • false if Maya is not currently referencing a file
int currentlyReadingFileVersion ( )
static

Each Maya file format version has a unique integer identifier.

Identifiers go up sequentially with each new file format.

This method returns the identifier for the version of the file that is currently being read into Maya.

Returns
The version of the file that is currently being read, or -1 if a file is not currently being read.
int latestMayaFileVersion ( )
static

Each Maya file format version has a unique integer identifier.

This method returns the identifier for the file format version that will be saved by this version of Maya.

Returns
The version of the file format saved by this version of Maya
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.
MStatus import ( const MString fileName,
const char *  type = NULL,
bool  preserveReferences = false,
const char *  nameSpace = NULL 
)
static

This method is obsolete. This method is not available in Python.

Deprecated:
Use the MFileIO::importFile method instead.

Import the scene elements from the given file into the current scene. This operation is similar to open, but instead of replacing the current scene with the one from the new file, it adds the elements from that file to the existing ones in the current scene.

Parameters
[in]fileNamename of the file from which to import objects
[in]typeif NULL, Maya will try to deduce the type of the file. if not NULL, it must contain the file type to use when importing the file.
[in]preserveReferencesBoolean to indicate whether the references need to be preserved.
[in]nameSpaceoptional name of the namespace to use when importing objects. Use NULL for default of no namespace.
Returns
const adsk::Data::Associations * metadata ( MStatus ReturnStatus = NULL)
static

This method is not available in Python.

Get the metadata associated with the current file.

Parameters
[out]ReturnStatusStatus code. See below.
Returns
Metadata associated with the file, NULL if there isn't any
Status Codes:
MStatus setMetadata ( const adsk::Data::Associations newMetadata)
static

This method is not available in Python.

Replace the existing file metadata with the given values.

Parameters
[in]newMetadataThe new associated metadata for the current file
Returns
Status code
Status Codes:
MStatus deleteMetadata ( )
static

This method is not available in Python.

Remove all metadata from the current file.

Note that this will delete all of the file-level metadata so it should be used with caution. If you want to delete specific metadata Channels then get the Associations, delete the Channel(s) and then set the modified Associations back using the setMetadata() method.

Returns
Status code
Status Codes:

The documentation for this class was generated from the following files:
  • MFileIO.h
  • MFileIO.cpp