00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "mayaSavePview.h"
00016
00017 #include <maya/MString.h>
00018 #include <maya/MFnPlugin.h>
00019 #include <maya/MFileIO.h>
00020 #include <maya/MArgParser.h>
00021 #include <maya/MArgList.h>
00022 #include <maya/MSyntax.h>
00023
00024 #include <stdlib.h>
00025
00026 #ifdef WIN32_VC
00027 #include <process.h>
00028 #endif
00029
00030
00031
00032
00033
00034
00035 MayaSavePview::
00036 MayaSavePview() {
00037 }
00038
00039
00040
00041
00042
00043
00044 MStatus MayaSavePview::
00045 doIt(const MArgList &args) {
00046 MStatus result;
00047
00048
00049 MSyntax syntax;
00050 syntax.addFlag("a", "animate");
00051
00052 MArgParser parser(syntax, args, &result);
00053 if (!result) {
00054 result.perror("arguments");
00055 return result;
00056 }
00057
00058 bool animate = parser.isFlagSet("a", &result);
00059 if (!result) {
00060 result.perror("isFlagSet");
00061 return result;
00062 }
00063
00064
00065 result = MFileIO::save(false);
00066 if (result != MS::kSuccess) {
00067 return result;
00068 }
00069
00070 MString filename = MFileIO::currentFile();
00071
00072 MString pview_args = "-cl";
00073 if (animate) {
00074 pview_args = "-cla";
00075 }
00076
00077 #ifdef WIN32_VC
00078
00079
00080 MString quoted = MString("\"") + filename + MString("\"");
00081 int retval = _spawnlp(_P_DETACH, "pview",
00082 "pview", pview_args.asChar(), quoted.asChar(), NULL);
00083 if (retval == -1) {
00084 return MS::kFailure;
00085 }
00086
00087 #else // WIN32_VC
00088
00089
00090
00091 MString command = MString("pview " + pview_args + MString(" \"") + filename + MString("\""));
00092
00093 int command_result = system(command.asChar());
00094 if (command_result != 0) {
00095 return MS::kFailure;
00096 }
00097 #endif // WIN32_VC
00098
00099 return MS::kSuccess;
00100 }
00101
00102
00103
00104
00105
00106
00107 void *MayaSavePview::
00108 creator() {
00109 return new MayaSavePview;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118 EXPCL_MISC MStatus
00119 initializePlugin(MObject obj) {
00120 MFnPlugin plugin(obj, "VR Studio", "1.0");
00121 MStatus status;
00122 status = plugin.registerCommand("pview", MayaSavePview::creator);
00123 if (!status) {
00124 status.perror("registerCommand");
00125 }
00126
00127 return status;
00128 }
00129
00130
00131
00132
00133
00134 EXPCL_MISC MStatus
00135 uninitializePlugin(MObject obj) {
00136 MFnPlugin plugin(obj);
00137 MStatus status;
00138 status = plugin.deregisterCommand("pview");
00139
00140 if (!status) {
00141 status.perror("deregisterCommand");
00142 }
00143 return status;
00144 }