Skip to content

Instantly share code, notes, and snippets.

@epicallan
Created February 8, 2015 10:07
Show Gist options
  • Save epicallan/000e12f4723266978f01 to your computer and use it in GitHub Desktop.
Save epicallan/000e12f4723266978f01 to your computer and use it in GitHub Desktop.
Openmaya API example
import maya.OpenMaya as om;
class MyClass(object):
def __init__(self):
#instantiating selection list function set
selectionList=om.MSelectionList();
#get currect selected object and put it into the selectionlist
om.MGlobal.getActiveSelectionList(selectionList);
self.getObject(selectionList);
def getObject(self,mylist):
#instantiating selection list iterator function set
iterator =om.MItSelectionList(mylist)
#object to store a dagpath
dagPath = om.MDagPath();
#object to store selected mesh
myObject = om.MObject();
#fucntion set to work with meshes
nodeFn=om.MFnDagNode();
#iterating through the selected meshes
while not iterator.isDone():
iterator.getDagPath(dagPath,myObject)
nodeFn.setObject(dagPath);
print "my object : "+ nodeFn.name();
print "my path : " + dagPath.fullPathName();
iterator.next();
mytype = myObject.apiTypeStr();
print"my type is : "+ mytype;
#vertex iterator
vertIterator = om.MItMeshVertex(dagPath,myObject)
mySpace =om.MSpace.kWorld;
#vector to store position of vertex
vec =om.MFloatVector();
#Point functionset that takes vector as an argument
vertPos = om.MPoint(vec);
while not vertIterator.isDone():
vertPos=vertIterator.position(mySpace)
print(vertPos.x);
myIndex=vertIterator.index();
print "vert index is "+ str(myIndex);
vertIterator.next();
omexample= MyClass();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment