Started getting into PyMEL now with Maya 2011 and it’s great but I have run into a little issue I can’t figure out how it works in this language.
I’m working on some scene check tools and currently need to know how many faces each material in the scene is being used on, and I get a list of connections but it is a mix of meshes and faces. So I need to treat those differently to get the value I want from them.
My initial idea was to use nodeType(), but MeshFace is not a node type and when used on them they return “mesh” just like nt.Mesh does.
Any simple idea on how I can filter these?
Another question, I can’t find any PyMEL implementation that give me the same info I get with findRelatedSkinCluster in MEL…
I can go from skinCluster to meshes and from skinClusters to bones, but I want to go from mesh to skinCluster like I can in MEL.
Suggestions?
faces = maya.cmds.polyListComponentConversion( listOfConnections, toFaces=True )
flatFaces = maya.cmds.filterExpand( faces, expand=True, sm=34 )
return len( flatFaces )
does that work for counting faces? It just normalizes you list to faces, and ignores having to treat things as different types.
Cheers, that worked perfect with some minor adjustment.
Removing the maya.cmds and changing the flag to toFace. :):
for future reference, you can use the builtin python command isinstance. this lets you check if an object is an instance of a particular class. for example:
>>> isinstance('foo', str)
True
so in pymel you could do:
>>> isinstance(PyNode('persp'), nt.DagNode)
True
since everything is a class and pymel provides a rich hierarchy of maya-specific classes for pretty much every object (as opposed to maya.cmds where everything is a string) you can use this to differentiate between just about anything, including MeshFace, MeshEdge, etc.
Thanks.
Still lots to learn about Python, I haven’t been using due to the initial implementation in Maya, but PyMEL is really good. Just got to get into the right mindset for it.
Anyone know where i can find an equivalent to MEL’s Mag in python commands?
In PyMEL there is .distanceTo() but I it’s too slow to be used in thousands of iterations in a scene.
Right now I’ve done it to old math way but a compiled function is usually faster then basic math.
you may try to convert the vector to pymel VectorN object and then using length() method to get the magnitude.
ex:
abc = VectorN(1,2,3) - VectorN(4,5,6)
print abc.length()
see if it’s faster.
Thanks, I ended up using the API MVector
Almost removed all PyMEL from the script now. Only a few areas where it was faster then doing the same thing in Python Commands. Reduced executing time to about 17% of the original script.