class MPxFileTranslator

Jump to documentation

Base Class for creating Maya File Translators. (OpenMaya) (OpenMayaMPx.py)

Inheritance:

MPxFileTranslator

public members:

enum MFileKind
kIsMyFileType
Translator understands how to read/write this file
kCouldBeMyFileType
Translator is not best available to read/write this file
kNotMyFileType
Translator does not understand how to read/write this file
enum FileAccessMode
kUnknownAccessMode
Unknown file access mode
kOpenAccessMode
Import data into new scene
kReferenceAccessMode
Reference data into current scene
kImportAccessMode
Import data into current scene
kSaveAccessMode
Save data
kExportAccessMode
Export data
kExportActiveAccessMode
Export active (selected) data
MPxFileTranslator ()
virtual ~MPxFileTranslator ()
virtual MStatus reader ( const MFileObject & file, const MString & optionsString, FileAccessMode mode)
virtual MStatus writer ( const MFileObject & file, const MString & optionsString, FileAccessMode mode)
virtual bool haveReadMethod () const
virtual bool haveWriteMethod () const
virtual bool haveNamespaceSupport () const
virtual bool haveReferenceMethod () const
virtual MString defaultExtension () const
virtual MString filter () const
virtual bool canBeOpened () const
virtual MPxFileTranslator::MFileKind identifyFile ( const MFileObject & file, const char* buffer, short size) const
static MPxFileTranslator::FileAccessMode fileAccessMode ()

Documentation

This class provides the connection to Maya by which user written file translators can be added as plug-ins.
Description

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.

Functions

MPxFileTranslator:: MPxFileTranslator ()

Description

The class constructor.

MPxFileTranslator:: ~MPxFileTranslator ()

Description

The class destructor.

MStatus MPxFileTranslator:: reader ( const MFileObject & file, const MString & optionsString, MPxFileTranslator::FileAccessMode mode)

Description

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.

Arguments

  • file the name of the file to read
  • optionsString a string representation of any file options
  • mode the method used to read the file - open or import

Return Value

  • MS::kSuccess if the read succeeds, and a failure code if it does not

MStatus MPxFileTranslator:: writer ( const MFileObject & file, const MString & optionsString, MPxFileTranslator::FileAccessMode mode)

Description

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.

Arguments

  • file the name of the file to write
  • optionsString a string representation of any file options
  • mode the method used to write the file - save, export, or export active.

Return Value

  • MS::kSuccess if the write succeeds, and a failure code if it does not

bool MPxFileTranslator:: haveReadMethod () const

Description

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.

Return Value

  • true if the class has a read method and false otherwise otherwise.

bool MPxFileTranslator:: haveReferenceMethod () const

Description

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 reference 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.

Return Value

  • true if the class has a reference method and false otherwise

bool MPxFileTranslator:: haveWriteMethod () const

Description

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.

Return Value

  • true if the class has a write method and false otherwise

bool MPxFileTranslator:: haveNamespaceSupport () const

Description

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 default 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.

Return Value

  • true if the class can deal with namespaces and false otherwise

MString MPxFileTranslator:: defaultExtension () const

Description

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.

Return Value A string containing the default extension of the translator, excluding the period at the beginning.

MString MPxFileTranslator:: filter () const

Description

This virtual method may be overloaded in a derived class to set the filter extension that will be used by the file dialog. If this method is not implemented in a derived class, the standard filter *.* will be returned by MPxFileTranslator and used by the file dialog.

Return Value A string containing the filter mask of the translator, Must be of the form *.obj

bool MPxFileTranslator:: canBeOpened () const

Description

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.

Return Value

  • true if the class can open and import files
  • false if the class can only import files

MPxFileTranslator::MFileKind MPxFileTranslator:: identifyFile ( const MFileObject &, const char*, short) const

Description

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.

Arguments

  • file the name of the file to check
  • buffer a pointer to the initial contents of the file
  • size the number of valid bytes in the buffer

Return Value

  • MFileKind::kIsMyFileType this file is understood by this translator
  • MFileKind::kNotMyFileType this file is not understood by this translator
  • MFileKind::kCouldBeMyFileType this file is understood by this translator, but this translator is not the best one to use for reading or writing it

MPxFileTranslator::FileAccessMode MPxFileTranslator:: fileAccessMode ()

Description

This routine returns the fileAccess mode maya is currently in.

Return Value

  • MPxFileTranslator::kUnknownAccessMode unknown file access mode
  • MPxFileTranslator::kReferenceAccessMode reference data into current scene
  • MPxFileTranslator::kImportAccessMode import data into current scene
  • MPxFileTranslator::kOpenAccessMode import data into new scene
  • MPxFileTranslator::kSaveAccessMode save data
  • MPxFileTranslator::kExportAccessMode export data
  • MPxFileTranslator::kExportActiveAccessMode export active (selected) data

Direct child classes:

- MPxMayaAsciiFilter

Autodesk® Maya® 2008 © 1997-2007 Autodesk, Inc. All rights reserved. doc++ Copyright