|
This is probably a little weird replying to my own post, but I have made some progress on getting information out, so I thought I would throw some snippets up on the off-chance someone else would find it useful.
Of course, if you are experienced with Maya Python, you realize by now that the problem that I was having was that I was not properly accessing the nodes in the DAG. So, the solution was to turn the names of the nodes, which are quite easy to get using maya.cmds.ls(), into actual objects that you can query. This, unfortunately, involves quite a bit of casting and subcasting, and seems like an awful lot of work, but it is what it is. Let me just put a couple snippets that helped me a bunch.
First, since I am working with names, I find that the easiest way to start the ball rolling is to use an MSelectionList. So, I have the following code
import maya.standalone
maya.standalone.initialize(name='python') import maya.cmd as cmds
import maya.OpenMaya as OpenMaya
# this will give us the names of all the nodes in the scene all_nodes = cmds.ls()
# use an MSelectionList to drive our queries s_list = OpenMaya.MSelectionList()
for node in all_nodes:
# this gives us the node type
node_type = cmds.nodeType(node)
# we can now do some selection and processing
if node_type == 'joint':
print 'Take a hit off this joint, dude!' # ok, bad pun
# this ensures that the list will only have the single member
s_list.clear()
# add our current node to the list
s_list.add(node)
# get the depend node
depend_node = OpenMaya.MObject()
s_list.getDependNode(0, depend_node)
# let's say we are a mesh, let's get the vertex data
if node_type != 'mesh':
continue
# select the mesh of interest
cmds.select(node)
# get the vertex data
vertex_data = []
num_verts = cmds.polyEvaluate(vertex=True)
vertex_data = [cmds.pointPosition("%s.vtx[%d]" % (node, i)) for i in range(num_verts)]
# now barf it out to the screen
print 'Vertices'
print str(vertex_data) # in [x, y, z] format
So, that is an extremely simpleminded way of getting some information out of the scene, just in case anyone else was as confused as I was. I may be adding some more snippets to this later.
|