i have a simple script that moves vertices. I want to be undo and redo
the actions. Can i create a DAG node to save information on the state
of the vertices before the movement and then I can use MDGModifier to
undo? This is what I had in mind:

#move a few verts on a geo and make it undoable
import maya.OpenMaya as om

class undoRedoTest():
    def __init__(self):
        self.__transPath = om.MDagPath()
        self.__dagModify = om.MDagModifier()
        self.__space = om.MSpace.kWorld

    def doIt(self, *args):
        om.MGlobal.selectByName('pPlane1')
        sList = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(sList)
        obj = om.MItSelectionList(sList, om.MFn.kGeometric)

        self.__dagModify.createNode(#node that saves info for current
position of vertices

        iter = om.MItMeshVertex(dagPath, components)
        fnMesh = om.MFnMesh(self.__transPath)
        doubleArray = om.MScriptUtil()
        doubleArray.createFromList([2, 3, 1], 1)

        while not iter.isDone():
            thisPt = iter.position()
            inPoint = om.MPoint(thisPt.x, thisPt.y, thisPt.z)
            outPoint = om.MPoint(0.0, 0.0, 0.0)
            fnMesh.getClosestPoint(inPoint, outPoint, self.__space)

            moveVec = om.MVector(doubleArray.asDoublePtr())
            iter.translateBy(moveVec, spc)

            iter.next()

    def redoIt(self):
        self.__dagModify.doIt()

    def undoIt(self):
        self.__dagModify.undoIt()

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to