AL_USDMaya  0.16.6
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
FileTranslatorBase.h File Reference

This file contains a few macros and templates to help automate the tedious boiler plate setup of Maya import/export plugins. More...

#include "AL/maya/FileTranslatorOptions.h"
#include "maya/MPxFileTranslator.h"
#include "maya/MGlobal.h"
#include "maya/MFileObject.h"

Go to the source code of this file.

Classes

class  AL::maya::FileTranslatorBase< T >
 A utility class that provides a 'unique' base class to derive new translator from. More...
 

Namespaces

 AL
 

Macros

#define AL_MAYA_TRANSLATOR_BEGIN(ClassName, TranslatorName, HaveRead, HaveWrite, DefaultExtension, FilterString)
 Macro to wrap some boiler plate creation of a file translator. More...
 
#define AL_MAYA_TRANSLATOR_END()   };
 Macro to wrap some boiler plate creation of a file translator.
 

Detailed Description

This file contains a few macros and templates to help automate the tedious boiler plate setup of Maya import/export plugins.

MAYA_TRANSLATOR_BEGIN(MyExporter, "My Exporter", true, true, "*.my", "*.my");
// specify the option names (These will uniquely identify the exporter options)
static const char* const kSomeBoolValue = "Some Bool Value";
static const char* const kSomeIntValue = "Some Int Value";
static const char* const kSomeFloatValue = "Some Float Value";
static const char* const kSomeStringValue = "Some String Value";
// provide a method to specify the import/export options
static MStatus specifyOptions(FileTranslatorOptions& options)
{
options.addFrame("My Exporter Options");
options.addBool(kSomeBoolValue, true);
options.addInt(kSomeIntValue, 42);
options.addFloat(kSomeFloatValue, 1.1111f);
options.addString(kSomeStringValue, "Cheesburgers");
}
// implement one or more of these:
MStatus reader(const MFileObject& file, const OptionsParser& options, FileAccessMode mode);
MStatus writer(const MFileObject& file, const OptionsParser& options, FileAccessMode mode);
MAYA_TRANSLATOR_END();
MStatus MyExporter::reader(const MFileObject& file, const OptionsParser& options, FileAccessMode mode)
{
// query your options
bool someBoolValue = options.getBool(kSomeBoolValue);
int someIntValue = options.getInt(kSomeIntValue);
float someFloatValue = options.getFloat(kSomeFloatValue);
MString someStringValue = options.getString(kSomeStringValue);
// import your data
return MS::kSuccess; // done!
}
MStatus MyExporter::writer(const MFileObject& file, const OptionsParser& options, FileAccessMode mode)
{
// query your options
bool someBoolValue = options.getBool(kSomeBoolValue);
int someIntValue = options.getInt(kSomeIntValue);
float someFloatValue = options.getFloat(kSomeFloatValue);
MString someStringValue = options.getString(kSomeStringValue);
// export your data
return MS::kSuccess; // done!
}

When you come to register your plugin, just do the following:

MStatus initializePlugin(MObject obj) {
MFnPlugin fn(obj);
return MyExporter::register(fn);
}
MStatus uninitializePlugin(MObject obj) {
MFnPlugin fn(obj);
return MyExporter::unregister(fn);
}

Macro Definition Documentation

#define AL_MAYA_TRANSLATOR_BEGIN (   ClassName,
  TranslatorName,
  HaveRead,
  HaveWrite,
  DefaultExtension,
  FilterString 
)
Value:
class ClassName : public AL::maya::FileTranslatorBase<ClassName> { \
public: \
static constexpr const char* const kTranslatorName = TranslatorName; \
static constexpr const char* const kClassName = #ClassName; \
static void* creator() { return new ClassName; } \
private: \
bool haveReadMethod() const { return HaveRead; } \
bool haveWriteMethod() const { return HaveWrite; } \
MString defaultExtension() const { return DefaultExtension; } \
MString filter() const { return FilterString; } \
public:
A utility class that provides a 'unique' base class to derive new translator from.
Definition: Common.h:47

Macro to wrap some boiler plate creation of a file translator.