Ok, just a quick example: there is an in depth one in the maya documentation: poly_modifier.py.
In a broad sense maya is a nodal application: there is 2 types of nodes* "A transform node is a type of DAG node which handles transformations (translate, rotate, and scale), while a shape node is a type of DAG node which handles geometry"* ( from API : /DAG_Hierarchy.htm ). The flow of data travels between connected attributes . The refresh evaluation/propagation in this network is done in a lazy way through a push and pull of a dirty bit attribute. When you want to support undo/redo you must understand how maya works: in mel or with the interface/UI you can create/Delete transform or dependencyNode, connect/disconnect attributes then get and set value. the API reflect these actions. you want to modify a polygonal shape( a mesh ) so quite logically you must use a dependency Modifier --> MDGModifier. code: http://pastebin.ubuntu.com/1044863/ of course you can use whatever iterator you see fit but it is important to initialize it with the dataOwner newMeshObj. in the end the MDGModifier will just write a new value from this meshdata into your target polygon Le jeudi 14 juin 2012 00:08:38 UTC+2, Serena Xu a écrit : > > 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
