class MPxMayaAsciiFilter

Jump to documentation

: public MPxFileTranslator Translator to output filtered Maya ASCII files. (OpenMaya) (OpenMayaMPx.py)

Inheritance:

MPxMayaAsciiFilter < MPxFileTranslator

public members:

MPxMayaAsciiFilter ()
virtual ~MPxMayaAsciiFilter ()
virtual bool haveWriteMethod () const
virtual bool haveReadMethod () const
virtual MStatus reader ( const MFileObject & file , const MString & optionsString, FileAccessMode mode)
virtual MStatus writer ( const MFileObject & file , const MString & optionsString, FileAccessMode mode)

protected members:

const MFileObject file () const
virtual MStatus processReadOptions (const MString & optionsString)
virtual MStatus processWriteOptions (const MString & optionsString)
virtual bool writesRequirements ( ) const
virtual bool writesCreateNode ( const MObject & node ) const
virtual bool writesSetAttr ( const MPlug & srcPlug ) const
virtual bool writesConnectAttr ( const MPlug & srcPlug, const MPlug & destPlug ) const
virtual bool writesDisconnectAttr ( const MPlug & srcPlug, const MPlug & destPlug ) const
virtual bool writesParentNode ( const MDagPath & parent, const MDagPath & child ) const
virtual bool writesSelectNode ( const MObject & node ) const
virtual bool writesFileReference ( const MFileObject & referenceFile ) const
virtual MStatus writePostHeader ( MPxMayaAsciiFilterOutput& fileIO )
virtual MStatus writePostRequires ( MPxMayaAsciiFilterOutput& fileIO )
virtual MStatus writePreCreateNodesBlock ( MPxMayaAsciiFilterOutput& fileIO )
virtual MStatus writePostCreateNodesBlock ( MPxMayaAsciiFilterOutput& fileIO )
virtual MStatus writePreConnectAttrsBlock ( MPxMayaAsciiFilterOutput& fileIO )
virtual MStatus writePostConnectAttrsBlock ( MPxMayaAsciiFilterOutput& fileIO )
virtual MStatus writePreTrailer ( MPxMayaAsciiFilterOutput& fileIO )

Inherited from 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

Output filtered Maya ASCII files.
Description

MPxMayaAsciiFilter allows the 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 to, for example, 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 metohds in MPxMayaAsciiFilter. A pseudo-code example is shown here:

MyAsciiFilter::writer(...)
{
	// do something before writing to file here
	...

	// we will now write to the file

	MStatus result = MPxMayaAsciiFilter::reader(...);
	
	if (result == MStatus::kSuccess)
	{
		...	// do something after writing the file here
	}

	return result;
}

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:

bool
MyAsciiFilter::writesCreateNode( const MObject& node )
{
	if (node.hasFn(MFn::kRenderLayer))
	{
		return true;
	}

	return false;
}

bool
MyAsciiFilter::writesConnectAttr( const MPlug& srcPlug,
								  const MPlug& destPlug )
{
	if (srcPlug.node().hasFn(MFn::kRenderLayer) ||
		dstPlug.node().hasFn(MFn::kRenderLayer))
	{
		return true;
	}

	return false;
}

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 and will not 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's 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:

MStatus
MyAsciiFilter::writePostCreateNodesBlock( MPxMayaAsciiFilterOutput& fileIO )
{
	fileIO << "exec(\"importRenderLayerFile \"MyLayerFile.maf\";\")\n";
}

In the above example, after the createNode block was output, the line

exec("importRenderLayerFile "MyLayerFile.maf");

is 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, Alias does not support such custom files as they will not, by definition, be standard Maya ASCII files.

Functions

MPxMayaAsciiFilter:: MPxMayaAsciiFilter ()

Description

The class constructor.

MPxMayaAsciiFilter:: ~MPxMayaAsciiFilter ()

Description

The class destructor.

bool MPxMayaAsciiFilter:: haveWriteMethod () const

Description

Overrides MPxFileTranslator::haveWriteMethod() to indicate that this translator has a write method. In general this should not be overridden.

Return Value

  • true

bool MPxMayaAsciiFilter:: haveReadMethod () const

Description

Overrides MPxFileTranslator::haveReadMethod() to indicate that this translator has a read method. In general this should not be overridden.

Return Value

  • true

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

Description

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.

Arguments

  • file The file to be read
  • optionsString Any file options to be handled. Passed to processReadOptions(), below
  • mode The access mode (read or import). Currently this is ignored

Return Value

  • MS::kSuccess file read was successful
  • MS::kFailure an error occurred while reading the file

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

Description

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.

Arguments

  • file The file to be read
  • optionsString Any file options to be handled. Passed to processWriteOptions(), below
  • mode The access mode (save, export, or export active). Currently this is ignored.

Return Value

  • MS::kSuccess file read was successful
  • MS::kFailure an error occurred while reading the file

const MFileObject MPxMayaAsciiFilter:: file () const

Description

Returns the MFileObject associated with the file currently being read or written, allowing access to the file's name, path and so on.

Arguments

Return Value

  • MFileObject The file object. Only valid while a read or write is happpening

MStatus MPxMayaAsciiFilter:: processReadOptions ( const MString & optionsString )

Description

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.

Arguments

  • optionsString The file options to be handled.

Return Value

  • MS::kSuccess Options were properly handled, and file read can commence. If any other value is returned, file read is aborted.

MStatus MPxMayaAsciiFilter:: processWriteOptions ( const MString & optionsString )

Description

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.

Arguments

  • optionsString The file options to be handled.

Return Value

  • MS::kSuccess Options were properly handled, and file read can commence. If any other value is returned, file write is aborted.

bool MPxMayaAsciiFilter:: writesRequirements ( ) const

Description

Determines if "requires" commands should be written in the file.

By default true is always returned.

Arguments

Return Value

  • bool true if "requires" commands should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesCreateNode ( const MObject & node ) const

Description

Determines if a "createNode" command should be written for a particular node.

By default this method returns true for all nodes.

Arguments

  • node The node in question.

Return Value

  • bool true if the createNode should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesSetAttr ( const MPlug & srcPlug ) const

Description

Determines if a "setAttr" command should be written for a particular node.

By default this method returns true for all plugs.

Arguments

  • srcPlug The plug to be set.

Return Value

  • bool true if the setAttr should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesConnectAttr ( const MPlug & srcPlug, const MPlug & destPlug ) const

Description

Determines if a "connectAttr" command should be written for a particular node.

By default this method returns true for all connections.

Arguments

  • srcPlug The source plug in the connection.
  • destPlug The destination plug in the connection.

Return Value

  • bool true if the connectAttr should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesDisconnectAttr ( const MPlug & srcPlug, const MPlug & destPlug ) const

Description

Determines if a "disconnectAttr" command should be written for a particular connection.

By default this method returns true for all connection.

Arguments

  • srcPlug The source plug in the connection.
  • destPlug The destination plug in the connection.

Return Value

  • bool true if the disconnectAttr should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesParentNode ( const MDagPath & parent, const MDagPath & child ) const

Description

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.

Arguments

  • parent The dag path to the parent.
  • child The dag path to the child.

Return Value

  • bool true if the disconnectAttr should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesSelectNode ( const MObject & node ) const

Description

Determines if a "select" command should be written for a particular node.

By default this method returns true for all nodes.

Arguments

  • node The node to select

Return Value

  • bool true if the select should be written; false otherwise.

bool MPxMayaAsciiFilter:: writesFileReference ( const MFileObject & referenceFile ) const

Description

Determines if a "fileReference" command should be written for a file.

By default this method returns true for all files.

Arguments

  • referenceFile The file to be referenced.

Return Value

  • bool true if the fileReference should be written; false otherwise.

MStatus MPxMayaAsciiFilter:: writePostHeader ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file after the header block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • bool true if the disconnectAttr should be written; false otherwise.

MStatus MPxMayaAsciiFilter:: writePostRequires ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file after the requires block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • MS::kSuccess Output was successfull.

MStatus MPxMayaAsciiFilter:: writePreCreateNodesBlock ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file before the create nodes block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • MS::kSuccess Output was successfull.

MStatus MPxMayaAsciiFilter:: writePostCreateNodesBlock ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file after the create nodes block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • MS::kSuccess Output was successfull.

MStatus MPxMayaAsciiFilter:: writePreConnectAttrsBlock ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file before the connect attrs block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • MS::kSuccess Output was successfull.

MStatus MPxMayaAsciiFilter:: writePostConnectAttrsBlock ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file after the connect attrs block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • MS::kSuccess Output was successfull.

MStatus MPxMayaAsciiFilter:: writePreTrailer ( MPxMayaAsciiFilterOutput& filterOutput )

Description

Allows data to be written out to the file before the trailer block.

By default this method does nothing.

Arguments

  • parent the output stream to be written to (using the << operator)

Return Value

  • MS::kSuccess Output was successfull.

This class has no child classes.


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