按照下面的代码,我首先尝试将对象追加到MObjectArray, 想要删除撤消功能。
撤消,重做工作正常..但是撤消仅删除数组/对象的第一个元素 不是所有的人。想知道出了什么问题以及在撤消功能中删除对象的最佳方法是什么。
.h
#include <maya/MPxCommand.h>
#include <maya/MArgList.h>
#include <maya/MObject.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MDagPath.h>
#include <maya/MFnMesh.h>
#include <maya/MPointArray.h>
#include <maya/MIntArray.h>
#include <maya/MItSelectionList.h>
#include <maya/MItMeshEdge.h>
#include <maya/MDagModifier.h>
class deleteObj : public MPxCommand
{
public:
deleteObj() {};
virtual MStatus doIt(const MArgList& argList);
static void* creator();
virtual MStatus redoIt();
virtual MStatus undoIt();
MObjectArray objectTransforms;
virtual bool isUndoable() const { return true; }
};
.cpp
#include <maya\MFnPlugin.h>
#include "undoredo.h"
MStatus deleteObj::doIt(const MArgList & argList)
{
return redoIt();
}
MStatus deleteObj::redoIt()
{
for (int j = 0; j < 3; j++)
{
MString cmd("maya.cmds.polyCube()");
MGlobal::executePythonCommand(cmd);
MSelectionList selection;
MGlobal::getActiveSelectionList(selection);
MObject selObj;
selection.getDependNode(j, selObj);
objectTransforms.append(selObj);
}
return MS::kSuccess;
}
MStatus deleteObj::undoIt()
{
for (unsigned int i = 0; i <objectTransforms.length(); i++)
{
MGlobal::deleteNode(objectTransforms[i]);
}
return MS::kSuccess;
}
void * deleteObj::creator()
{
return new deleteObj;
}
MStatus initializePlugin(MObject obj)
{
MFnPlugin plugin(obj, "Atri Dave", "1.0", "Any");
MStatus status = plugin.registerCommand("deleteObj", deleteObj::creator);
CHECK_MSTATUS_AND_RETURN_IT(status);
return status;
}
MStatus uninitializePlugin(MObject obj)
{
MFnPlugin plugin(obj);
MStatus status = plugin.deregisterCommand("deleteObj");
CHECK_MSTATUS_AND_RETURN_IT(status);
return status;
}