#ifndef _MSimple #define _MSimple // //- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc., and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright law // and by international treaties. // // The Data may not be disclosed or distributed to third parties or be // copied or duplicated, in whole or in part, without the prior written // consent of Autodesk. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the following // disclaimer, must be included in all copies of the Software, in whole // or in part, and all derivative works of the Software, unless such copies // or derivative works are solely in the form of machine-executable object // code generated by a source language processor. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, // OR ARISING FROM A COURSE OF DEALING, USAGE, OR TRADE PRACTICE. IN NO // EVENT WILL AUTODESK AND/OR ITS LICENSORS BE LIABLE FOR ANY LOST // REVENUES, DATA, OR PROFITS, OR SPECIAL, DIRECT, INDIRECT, OR // CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS LICENSORS HAS // BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES. // ========================================================================== //+ // // CLASS: MSimple // // ***************************************************************************** // // ***************************************************************************** #if defined __cplusplus // ***************************************************************************** // INCLUDED HEADER FILES #include #include #include #include #include ///(OpenMaya) /** This header contains two macros that can be used to simplify the creation of plug-in commands. DeclareSimpleCommand( className, vendorName, version ) To use this macro, you provide it with the name of the class that should be derived from MPxCommand, the name of your organisation, and the version number of the plug-in. The macro expands to all the code necessary to create a command except for the command's "doIt" method. You need to provide a function with the prototype MStatus className::doIt( const MArgList& ) The macro will generate a class with the given classname that is derived from MPxCommand. It will also generate the following methods: void* className::creator() MStatus initializePlugin( MObject ) MStatus uninitializePlugin( MObject ) You can also call methods inherited from MPxCommand such as "setResult", "displayWarning", and "displayError". DeclareSingle( functionPtr ) To use this macro you must write a function with the prototype: MStatus functionPtr ( const MArgList& ) The macro expands to all the code necessary to create a basic non-undoable command that calls "functionPtr" from it's doIt method. One limitation of using this macro is that since "functionPtr" is not a member of the class derived from MPxCommand, it cannot call methods (like setResult) that are inherited from that class. The macro will generate a class called _DoItCmd which is derived from MPxCommand. It also generate the following methods: void* _DoItCmd::creator() MStatus _DoItCmd::doIt( const MArgList& args ) MStatus initializePlugin( MObject ) MStatus uninitializePlugin( MObject ) */ #define DeclareSimpleCommand( _className, _vendor, _version ) \ class _className : public MPxCommand { \ public: \ _className() {}; \ virtual MStatus doIt ( const MArgList& ); \ static void* creator(); \ }; \ void* _className::creator() \ { \ return new _className; \ } \ MStatus initializePlugin( MObject _obj ) \ { \ MFnPlugin plugin( _obj, _vendor, _version ); \ MStatus stat; \ stat = plugin.registerCommand( #_className, \ _className::creator ); \ if ( !stat ) \ stat.perror("registerCommand"); \ return stat; \ } \ MStatus uninitializePlugin( MObject _obj ) \ { \ MFnPlugin plugin( _obj ); \ MStatus stat; \ stat = plugin.deregisterCommand( #_className ); \ if ( !stat ) \ stat.perror("deregisterCommand"); \ return stat; \ } #define DeclareSingle( _fnptr ) \ class _DoItCmd : public MPxCommand { \ public: \ _DoItCmd() {}; \ virtual MStatus doIt ( const MArgList& ); \ static void* creator(); \ }; \ void* _DoItCmd::creator() \ { \ return new _DoItCmd; \ } \ MStatus _DoItCmd::doIt( const MArgList& args ) \ { \ return _fnptr(args); \ } \ MStatus initializePlugin( MObject _obj ) \ { \ MFnPlugin _plugin( _obj ); \ MStatus stat; \ stat = _plugin.registerCommand( #_fnptr, \ _DoItCmd::creator ); \ if ( !stat ) \ stat.perror("registerCommand"); \ return stat; \ } \ MStatus uninitializePlugin( MObject _obj ) \ { \ MFnPlugin plugin( _obj ); \ MStatus stat; \ stat = plugin.deregisterCommand( #_fnptr ); \ if ( !stat ) \ stat.perror("deregisterCommand"); \ return stat; \ } // ***************************************************************************** #endif /* __cplusplus */ #endif /* _MSimple */