//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ /* file : fileIOMsgCmd.cpp class: PreLoad ---------------------- This is an example to demonstrate the usages of : MString MFileIO::beforeImportFile(MStatus*); MString MFileIO::beforeOpenFile(MStatus*); MString MFileIO::beforeExportFile(MStatus*); MString MFileIO::beforeReferenceFile(MStatus*); Return value of MS::kSuccess indicates correct value returns */ #include #include #include #include #include #include #include #include class PreLoad : public MPxCommand { public: // callback functions. static void preOpenFunc(void* clientData); static void preImportFunc(void* clientData); static void preSaveFunc(void* clientData); static void preExportFunc(void* clientData); static void preReferenceFunc(void* clientData); virtual MStatus doIt( const MArgList& ); static void *creator(); static MSyntax newSyntax(); static MCallbackIdArray& getCallbackIds(); private: //callback ids .. used later for removal static MCallbackIdArray ids; }; MCallbackIdArray PreLoad::ids; // This is the call back function at Pre Import stage. void PreLoad::preOpenFunc(void* clientData) { MString msg = "FILE TO BE OPENED IS "; MStatus status = MS::kSuccess; MString file = MFileIO::beforeOpenFilename(&status); // check the status and then append accordingly msg += ( status == MS::kSuccess) ? file : "ERROR: Could not be retrieved" ; MGlobal::displayInfo(msg); } // This is the call back function at Pre Import stage. void PreLoad::preImportFunc(void* clientData) { MString msg = "PRE IMPORT FILE IS "; MStatus status = MS::kSuccess; MString file = MFileIO::beforeImportFilename(&status); // check the status and then append accordingly msg += ( status == MS::kSuccess) ? file : "ERROR: Could not be retrieved" ; MGlobal::displayInfo(msg); } // This is the call back function at Pre Save stage. void PreLoad::preSaveFunc(void* clientData) { MString msg = "FILE TO BE SAVED IS"; MStatus status = MS::kSuccess; MString file = MFileIO::beforeSaveFilename(&status); //check the status and then append accordingly msg += ( status == MS::kSuccess) ? file : "ERROR: File name could not be retrieved" ; MGlobal::displayInfo(msg); } // This is the call back function at Pre Export stage. void PreLoad::preExportFunc(void* clientData) { MString msg = "FILE TO BE EXPORTED IS"; MStatus status = MS::kSuccess; MString file = MFileIO::beforeSaveFilename(&status); // check the status and then append accordingly msg += ( status == MS::kSuccess) ? file : "ERROR: File name could not be retrieved" ; MGlobal::displayInfo(msg); } // This is the call back function at Pre Reference stage. void PreLoad::preReferenceFunc(void* clientData) { MString msg = "FILE TO BE REFERENCED IS"; MStatus status = MS::kSuccess; MString file = MFileIO::beforeReferenceFilename(&status); //check the status and then append accordingly msg += ( status == MS::kSuccess) ? file : "ERROR: File name could not be retrieved" ; MGlobal::displayInfo(msg); } MStatus PreLoad::doIt( const MArgList& ) { MStatus status = MS::kSuccess; MGlobal::displayInfo("PLUGIN LOADED"); // add the function call backs // and store call back ids for removal later ids.append(MSceneMessage::addCallback ( MSceneMessage::kBeforeOpen, preOpenFunc )) ; ids.append(MSceneMessage::addCallback ( MSceneMessage::kBeforeImport, preImportFunc )) ; ids.append(MSceneMessage::addCallback ( MSceneMessage::kBeforeSave, preSaveFunc )) ; ids.append(MSceneMessage::addCallback ( MSceneMessage::kBeforeExport, preExportFunc )) ; ids.append(MSceneMessage::addCallback ( MSceneMessage::kBeforeReference, preReferenceFunc )) ; return status ; } void* PreLoad::creator() { return new PreLoad; } MCallbackIdArray& PreLoad::getCallbackIds() { return ids; } // standard initialize and uninitialize functions MStatus initializePlugin(MObject obj) { MFnPlugin pluginFn(obj, "Alias", "6.0"); MStatus status; status = pluginFn.registerCommand("fileIOMsgCmd", PreLoad::creator); if( !status) status.perror("register Command failed"); return status; } MStatus uninitializePlugin ( MObject obj ) { MFnPlugin pluginFn(obj); MStatus status = MS::kSuccess; //remove call backs MMessage::removeCallbacks(PreLoad::getCallbackIds()); status = pluginFn.deregisterCommand( "fileIOMsgCmd"); return status; }