#include <MPxFileTranslator.h>
Base Class for creating Maya File Translators.
This class provides the connection to Maya by which user written file translators can be added as plug-ins.
This class provides a base class from which one derives in order to implement Maya "File Translator Plug-Ins." A file translator plug-in allows Maya to read or write 3rd party file formats.
The identifyFile method is called whenever Maya's file save or restore dialogs are run, and identifyFile uses the filename and first few bytes of the file to determine whether it is of a type supported by the translator. If it is, then Maya will display the file with the "name" and "icon" specified as arguments to MFnPlugin::registerFileTranslator.
If an attempt is made to read the file, the "reader" method in the derived class is called, if an attempt is made to write the file, the "writer" method is called.
Public Types | |
enum | MFileKind { kIsMyFileType, kCouldBeMyFileType, kNotMyFileType } |
How the translator identifies this file. More... | |
enum | FileAccessMode { kUnknownAccessMode, kOpenAccessMode, kReferenceAccessMode, kImportAccessMode, kSaveAccessMode, kExportAccessMode, kExportActiveAccessMode } |
Type of file access. More... | |
Public Member Functions | |
MPxFileTranslator () | |
The class constructor. | |
virtual | ~MPxFileTranslator () |
The class destructor. | |
virtual MStatus | reader (const MFileObject &file, const MString &optionsString, FileAccessMode mode) |
This routine is called by Maya when it is necessary to load a file of a type supported by this translator. More... | |
virtual MStatus | writer (const MFileObject &file, const MString &optionsString, FileAccessMode mode) |
This routine is called by Maya when it is necessary to save a file of a type supported by this translator. More... | |
virtual bool | haveReadMethod () const |
This routine is called by Maya while it is executing in the MPxFileTranslator constructor. More... | |
virtual bool | haveWriteMethod () const |
This routine is called by Maya while it is executing in the MPxFileTranslator constructor. More... | |
virtual bool | haveNamespaceSupport () const |
When a file is imported or referenced into an existing scene, there is the possibility that nodes in the incoming file will have the same names as nodes already in the scene. More... | |
virtual bool | haveReferenceMethod () const |
This method is called by Maya to see if the translator implements its own custom file referencing. More... | |
virtual MString | defaultExtension () const |
This routine is called by Maya whenever it needs to know the default extension of a translator. More... | |
virtual MString | filter () const |
This virtual method may be overloaded in a derived class to set the filter extension that will be used by the file dialog. More... | |
virtual bool | canBeOpened () const |
This routine is called by Maya while it is executing in the MPxFileTranslator constructor. More... | |
virtual MPxFileTranslator::MFileKind | identifyFile (const MFileObject &file, const char *buffer, short size) const |
This routine is called by Maya when a file selection dialog accesses a new directory. More... | |
Static Public Member Functions | |
static MPxFileTranslator::FileAccessMode | fileAccessMode () |
This routine returns the fileAccess mode maya is currently in. More... | |
enum MFileKind |
enum FileAccessMode |
Type of file access.
|
virtual |
This routine is called by Maya when it is necessary to load a file of a type supported by this translator.
This virtual method must be overloaded in derived classes, as the default version defined in MPxFileTranslator simply fails unconditionally. The only parameter is an MFileObject that contains the pathname of the file to be loaded. This routine is responsible for reading the contents of the given file, and creating Maya objects via API or MEL calls to reflect the data in the file.
[in] | file | the name of the file to read |
[in] | optionsString | a string representation of any file options |
[in] | mode | the method used to read the file - open or import |
Reimplemented in MPxMayaAsciiFilter.
|
virtual |
This routine is called by Maya when it is necessary to save a file of a type supported by this translator.
This virtual method must be overloaded in derived classes, as the default version defined in MPxFileTranslator simply fails unconditionally. The only parameter is an MFileObject that contains the pathname of the file to be written to. This routine is responsible for traversing all objects in the current Maya scene, and writing a representation to the given file in the supported format.
It is not essential that all information in the current Maya scene be written out, although if it is not, the scene will not be recreated when this file is read via the "reader" method.
[in] | file | the name of the file to write |
[in] | optionsString | a string representation of any file options |
[in] | mode | the method used to write the file - save, export, or export active. |
Reimplemented in MPxMayaAsciiFilter.
|
virtual |
This routine is called by Maya while it is executing in the MPxFileTranslator constructor.
Maya uses this entry point to query the translator and determine if it provides a reader method.
This virtual method must be overloaded in derived classes if a reader method exists, as the default version defined in MPxFileTranslator unconditionally returns false.
Reimplemented in MPxMayaAsciiFilter.
|
virtual |
This routine is called by Maya while it is executing in the MPxFileTranslator constructor.
Maya uses this entry point to query the translator and determine if it provides a write method.
This virtual method must be overloaded in derived classes if a writer method exists, as the default version defined in MPxFileTranslator unconditionally returns false.
Reimplemented in MPxMayaAsciiFilter.
|
virtual |
When a file is imported or referenced into an existing scene, there is the possibility that nodes in the incoming file will have the same names as nodes already in the scene.
Although DAG nodes may legally have the same name so long as their DAG paths are different, in all other cases node names must be unique.
Maya has a number of different algorithms which the user may select to resolve name clashes. (See the file command for more details.) Some of these algorithms involve creating a separate namespace for the incoming file and placing some or all of its nodes within that namespace.
As some translators may have difficulty dealing with namespaces, Maya will first call the translator's haveNamespaceSupport() method to see if it can handle them.
If the user requests that namespaces be used to resolve clashes and the translator does not support namespaces, then Maya will simply place all incoming nodes into the current namespace and it will be up to the translator to ensure that no clashes occur, otherwise there will be errors during the import/reference.
If a translator can deal with having Maya placing some or all of a file's nodes into a separate namespace, then its derived class should override this virtual method to return true.
By default the method returns false.
|
virtual |
This method is called by Maya to see if the translator implements its own custom file referencing.
If this function returns true, every time a file of this translator's type is referenced and its parent is being saved or exported the write method of this translator will be called, so the custom file referencing can add information to its files.
If it returns false, Maya's file referencing system will be used by default.
This function returns false by default.
|
virtual |
This routine is called by Maya whenever it needs to know the default extension of a translator.
This virtual method may be overloaded in derived classes if a default extension exists, as the default version defined in MPxFileTranslator unconditionally returns an empty string.
|
virtual |
This virtual method may be overloaded in a derived class to set the filter extension that will be used by the file dialog.
If the defaultExtension method is not implemented in a derived class, the standard filter *.* will be returned by MPxFileTranslator and used by the file dialog. If defaultExtension is implemented in a derived class, that extension will be used in the proper format.
|
virtual |
This routine is called by Maya while it is executing in the MPxFileTranslator constructor.
Maya uses this entry point to query the translator and determine if it can open files. The default is true.
|
virtual |
This routine is called by Maya when a file selection dialog accesses a new directory.
It will potentially be called once for every file in the directory.
The routine is given an MFileObject indicating the file being checked, as well as a pointer to the initial file contents. The size parameter indicates the number of bytes available at the pointer location.
This routine must use this data to determine if the file is of a type supported by this translator. This virtual method must be overloaded in derived classes, as the default version defined in MPxFileTranslator unconditionally returns kNotMyFileType.
A typical use of this method is to check the file extension of the file in question, and return a status indicating whether or not the file is of the type expected by this MPxFileTranslator. See the plugin example animImportExport for an example.
[in] | file | the name of the file to check |
[in] | buffer | a pointer to the initial contents of the file |
[in] | size | the number of valid bytes in the buffer |
|
static |
This routine returns the fileAccess mode maya is currently in.