I'm probably a little in over my head, but I'm starting to get familiar with the api, and I'm really not grasping the difference between function sets and iterators. They seem to be used in much the same way. could someone please give me some basic examples that help describe their differences, and how to know when you need one vs the other.
Thanks
Kev
Hey Kev,
The official docs describe the API structure in detail, but in a nutshell...
The basic object is an opaque handle, like an identifier, that can't do much of anything other than represent itself in memory.
Then you have function sets which are decoupled from the object handles and group together functions for specific types or purposes. Such as working with a handle for a mesh, or a curve. You attach an object to the function set, and then you can operate on it.
Iterators do just that one specific thing. They are type specific ways to loop over something that is a container for something else. Such as the selections in a selection list, or verts, or CVs.
Keep in mind that the python API (v1) is a very direct binding to its C++ counterpart. So it would be natural for the concepts in that api to seem a bit strange to a pure python programmer.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/edac5634-3c96-481c-9892-03ee52767adf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think it's mainly just the iterators that I'm not really clear on. The docs seem to hit on the function sets, but I'm not really finding anything that explains iterators in detail, maybe Im missing it?
so would you use a function set to access points of a polymesh, then use an iterator to iterate through each point? is there a common direct useage between the function sets & iterators? or is it just case by case?
anyhow. I'm working with the 2.0 python api right now, since I just noticed yesterday that quite a few more classes were added with sp4.
With the code below, which would be the proper way to write it? I feel like the first way is best. what does the iterator really contribute? speed? am I even using the iter correctly? ;)
#=======================================
import maya.api.OpenMaya as om2
selList = om2.MSelectionList( om2.MGlobal.getActiveSelectionList() )
dagList = om2.MSelectionList()
for i in range( selList.length() ):
dagList.add( selList.getDagPath(i) )
print dagList
#=======
selList = om2.MSelectionList( om2.MGlobal.getActiveSelectionList() )
selIter = om2.MItSelectionList( selList )
dagList = om2.MSelectionList()
while not selIter.isDone():
dagList.add( selIter.getDagPath() )
selIter.next()
print dagList
#=======================================
Thanks!
Kev
Selecting multiple types of object components
When multiple types of object components are selected, e.g. edges and vertices, an MSelectionList that has been assigned the active selection list will contain only the final type of component selected. For example if edges were selected and then vertices were shift-selected the MSelectionList representing the active selection list will contain one MObject representing the vertex components.
Workaround
MItSelectionList list will differentiate between the different components selected and can be used to identify all of the various components selected.
MItSelectionList::getDagPath()
MItSelectionList::getDagPath() will always return the original dagPath of an instanced node. For example, if two shape nodes are selected and their dagPaths are:
pCube1|pCubeShape1 pCube2pCube2|pCubeShape1getDagPath() will return:
pCube1|pCubeShape1 pCube1pCube1|pCubeShape1for each object in the list.
Workaround
MSelectionList::getDagPath() will return the correct dagPath for each object in the list.
Kev
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6ed87828-bc64-4f4c-8774-312039ae7d9a%40googlegroups.com.