#include <MPxMayaAsciiFilter.h>
Translator to output filtered Maya ASCII files.
MPxMayaAsciiFilter allows output to the Maya ASCII (.ma) file format to be filtered by a plug-in. The file is output using the same internal mechanism that is used for normal Maya ASCII output, but allows your plug-in to prevent certain lines (such as createNodes or connectAttrs) from being output to the file. In addition, it allows you to write directly to the file at specific points during output.
MPxMayaAsciiFilter allows your plug-in to write out files similar to Maya ASCII in a custom format. It can be used, for example, to partition a scene into several files, each of which has been filtered to write out different parts of the scene. Note that the order of the file cannot be changed - for example, connectAttrs are always written after createNodes - but it does allow you to control which connectAttrs and createNodes are output.
MPxMayaAsciiFilter inherits from MPxFileTranslator. It overrides the haveWriteMethod(), haveReadMethod(), reader(), and writer() methods in MPxFileTranslator in such a way that the internal Maya mechanism for reading and writing Maya ASCII files is used. Because of this, it is not advised that you override these methods in your plug-in. If you do, make sure you first call these methods in MPxMayaAsciiFilter. A pseudo-code example is shown here:
To determine if a given line should be output, override the methods writesCreateNode(), writesSetAttr() and so on. Each of these methods takes as its arguments the relevant data which is about to be processed and your plug-in can use this to determine whether or not the line will be output.
For example, you may want to write out everything but render layer data. The code to do this might look something like what is shown here:
Note that writesConnectAttr() has to be overridden as well (as would writesSetAttr(), writesSelectAttr(), and so on). This is because each line is handled separately, and nothing clever is done in the base class' implementation of writesConnectAttr(), such as having a default behaviour of only outputting connectAttrs for nodes that are being output. This gives you the most flexible control over what will be written.
If you were using this class to save a segmented file, a master file might have to know about the locations of each of the segments. If your file saved everything but render layers in one file, and render layers in another, the first file might need to contain a pointer to the second, so that when the first file is loaded the second gets read into memory too. To do this, you would use MPxMayaAsciiFilter's ability to write directly to the stream during file output.
You can write to the stream during output by overriding the methods writePreCreateNodesBlock(), writePostCreateNodesBlock() and so on. These give you a simple mechanism to write directly to the file. Each of these methods take an MPxMayaAsciiFilterOutput as its only argument. To write to the file, simply use the output operator (MPxMayaAsciiFilterOutput::operator<<() ) and output the string you wish.
In the example above, the pointer to the render layer file might be inserted into the main file after all nodes have been created. The code to do this would look something like what is shown here:
In the above example, after the createNode block was output, the line
was output. When the file is read in, Maya would reach the line above and execute it like any other MEL command. It is assumed in this example that there would be a custom command plug-in called importRenderLayerFile which would do the work of actually importing the layer file.
Note: MPxMayaAsciiFilter gives you the ability to create your own custom file formats based on standard Maya ASCII files. However, Autodesk does not support such custom files as they will not, by definition, be standard Maya ASCII files.
Public Member Functions | |
MPxMayaAsciiFilter () | |
The class constructor. | |
virtual | ~MPxMayaAsciiFilter () |
The class destructor. | |
virtual bool | haveWriteMethod () const |
Overrides MPxFileTranslator::haveWriteMethod() to indicate that this translator has a write method. More... | |
virtual bool | haveReadMethod () const |
Overrides MPxFileTranslator::haveReadMethod() to indicate that this translator has a read method. More... | |
virtual MStatus | reader (const MFileObject &file, const MString &optionsString, FileAccessMode mode) |
Reader method for the ascii filter translator. More... | |
virtual MStatus | writer (const MFileObject &file, const MString &optionsString, FileAccessMode mode) |
Writer method for the ascii filter translator. More... | |
![]() | |
MPxFileTranslator () | |
The class constructor. | |
virtual | ~MPxFileTranslator () |
The class destructor. | |
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... | |
Protected Member Functions | |
const MFileObject | file () const |
Returns the MFileObject associated with the file currently being read or written, allowing access to the file's name, path and so on. More... | |
virtual MStatus | processReadOptions (const MString &optionsString) |
Allows the translator to handle any options passed into the reader() method, above. More... | |
virtual MStatus | processWriteOptions (const MString &optionsString) |
Allows the translator to handle any options passed into the reader() method, above. More... | |
virtual bool | writesRequirements () const |
Determines if "requires" commands should be written in the file. More... | |
virtual bool | writesMetadata () const |
Asserts that "dataStructure/addMetadata/applyMetadata" commands should be written in the file. More... | |
virtual bool | writesCreateNode (const MObject &node) const |
Determines if a "createNode" command should be written for a particular node. More... | |
virtual bool | writesSetAttr (const MPlug &srcPlug) const |
Determines if a "setAttr" command should be written for a particular node. More... | |
virtual bool | writesConnectAttr (const MPlug &srcPlug, const MPlug &destPlug) const |
Determines if a "connectAttr" command should be written for a particular node. More... | |
virtual bool | writesDisconnectAttr (const MPlug &srcPlug, const MPlug &destPlug) const |
Determines if a "disconnectAttr" command should be written for a particular connection. More... | |
virtual bool | writesParentNode (const MDagPath &parent, const MDagPath &child) const |
Determines if a "parent" command should be written for a particular parent and child. More... | |
virtual bool | writesSelectNode (const MObject &node) const |
Determines if a "select" command should be written for a particular node. More... | |
virtual bool | writesFileReference (const MFileObject &referenceFile) const |
Determines if a "fileReference" command should be written for a file. More... | |
virtual MStatus | writePostHeader (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file after the header block. More... | |
virtual MStatus | writePostRequires (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file after the requires block. More... | |
virtual MStatus | writePreCreateNodesBlock (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file before the create nodes block. More... | |
virtual MStatus | writePostCreateNodesBlock (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file after the create nodes block. More... | |
virtual MStatus | writePreConnectAttrsBlock (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file before the connect attrs block. More... | |
virtual MStatus | writePostConnectAttrsBlock (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file after the connect attrs block. More... | |
virtual MStatus | writePreTrailer (MPxMayaAsciiFilterOutput &fileIO) |
Allows data to be written out to the file before the trailer block. More... | |
Additional Inherited Members | |
![]() | |
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... | |
![]() | |
static MPxFileTranslator::FileAccessMode | fileAccessMode () |
This routine returns the fileAccess mode maya is currently in. More... | |
|
virtual |
Overrides MPxFileTranslator::haveWriteMethod() to indicate that this translator has a write method.
In general this should not be overridden.
Reimplemented from MPxFileTranslator.
|
virtual |
Overrides MPxFileTranslator::haveReadMethod() to indicate that this translator has a read method.
In general this should not be overridden.
Reimplemented from MPxFileTranslator.
|
virtual |
Reader method for the ascii filter translator.
In general this should not be overridden, since internal Maya methods are called in this method.
Note: To process any options passed in in the optionsString variable, subclasses should override the processReadOptions() method, below.
[in] | file | The file to be read |
[in] | optionsString | Any file options to be handled. Passed to processReadOptions(), below |
[in] | mode | The access mode (read or import). Currently this is ignored |
Reimplemented from MPxFileTranslator.
|
virtual |
Writer method for the ascii filter translator.
In general this should not be overridden, since internal Maya methods are called in this method.
Note: To process any options passed in in the optionsString variable, subclasses should override the processWriteOptions() method, below.
[in] | file | The file to be read |
[in] | optionsString | Any file options to be handled. Passed to processWriteOptions(), below |
[in] | mode | The access mode (save, export, or export active). Currently this is ignored. |
Reimplemented from MPxFileTranslator.
|
protected |
Returns the MFileObject associated with the file currently being read or written, allowing access to the file's name, path and so on.
Allows the translator to handle any options passed into the reader() method, above.
This call is made before the file is actually read. The default implementation does nothing.
[in] | optionsString | The file options to be handled. |
Allows the translator to handle any options passed into the reader() method, above.
This call is made before the file is actually read. The default implementation does nothing.
[in] | optionsString | The file options to be handled. |
|
protectedvirtual |
Determines if "requires" commands should be written in the file.
By default true is always returned.
|
protectedvirtual |
Asserts that "dataStructure/addMetadata/applyMetadata" commands should be written in the file.
Normally these are always written but you may want to override this to prevent metadata from being added to Maya files if you export it in other ways.
|
protectedvirtual |
Determines if a "createNode" command should be written for a particular node.
By default this method returns true for all nodes.
[in] | node | The node in question. |
|
protectedvirtual |
Determines if a "setAttr" command should be written for a particular node.
By default this method returns true for all plugs.
[in] | srcPlug | The plug to be set. |
Determines if a "connectAttr" command should be written for a particular node.
By default this method returns true for all connections.
[in] | srcPlug | The source plug in the connection. |
[in] | destPlug | The destination plug in the connection. |
Determines if a "disconnectAttr" command should be written for a particular connection.
By default this method returns true for all connection.
[in] | srcPlug | The source plug in the connection. |
[in] | destPlug | The destination plug in the connection. |
Determines if a "parent" command should be written for a particular parent and child.
By default this method returns true for all parents and children.
[in] | parent | The dag path to the parent. |
[in] | child | The dag path to the child. |
|
protectedvirtual |
Determines if a "select" command should be written for a particular node.
By default this method returns true for all nodes.
[in] | node | The node to select |
|
protectedvirtual |
Determines if a "fileReference" command should be written for a file.
By default this method returns true for all files.
[in] | referenceFile | The file to be referenced. |
|
protectedvirtual |
Allows data to be written out to the file after the header block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |
|
protectedvirtual |
Allows data to be written out to the file after the requires block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |
|
protectedvirtual |
Allows data to be written out to the file before the create nodes block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |
|
protectedvirtual |
Allows data to be written out to the file after the create nodes block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |
|
protectedvirtual |
Allows data to be written out to the file before the connect attrs block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |
|
protectedvirtual |
Allows data to be written out to the file after the connect attrs block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |
|
protectedvirtual |
Allows data to be written out to the file before the trailer block.
By default this method does nothing.
[in] | filterOutput | the output stream to be written to (using the << operator) |