getElements from MFnSingleIndexedComponent

114 views
Skip to first unread message

ynedelin

unread,
Nov 4, 2013, 2:27:14 PM11/4/13
to python_in...@googlegroups.com
Hey guys
I do not use OpenMaya very often so I need an advise here, I am writing a few functions to deal with skin weights and all works great as long as I do not change the components. I would like to change components for the setWeights.

Right now I create the variables I need and then run the MFnSkinCluster.getWeights.
 
So it looks sort of like this:

apiComponents = om.MFnSingleIndexedComponent().create(om.MFn.kMeshVertComponent)
skinCluster = omAnim.MFnSkinCluster(om.MObject())

skinCluster.getWeights(
                skinPath,
                apiComponents,
                weights,
                influenceCount)

Good!

Now I would like to know what is inside the apiComponents, and hopefully change it. I assume this is MFnSingleIndexedComponent object, therefore I should be able to run something like

vertexIndexList = om.MIntArray()
apiComponents.getElements(vertexIndexList)


But I get this error
#     self.apiComponents.getElements(vertexIndexList)
#   File "c:\buildforge\Maya_2013_Win64\build\work\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 1529, in <lambda>
#   File "c:\buildforge\Maya_2013_Win64\build\work\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 54, in _swig_getattr
# AttributeError: getElements #

please shed some light on how this supposed to work .

thank you

Yury




ynedelin

unread,
Nov 4, 2013, 3:04:38 PM11/4/13
to python_in...@googlegroups.com
After keep looking into this I realized that my apiComponents is actually a MObject, but how can I use it?

Paul Molodowitch

unread,
Nov 5, 2013, 10:20:06 AM11/5/13
to python_inside_maya
The relationship between MObjects + MFn function sets is one of the stranger features of the OpenMaya API, and can be hard to wrap your head around.  Basically, the mobject represents the actual "data", is is generally what is passed into / from the various methods, while the MFns can be thought of as classes used to "decode" the data, so that you can actually interact with them.  Therefore, before you can actually do anything with an MObject, you will often need to cast it into the appropriate MFn function set.

In your case, since MFnSingleIndexedComponent.create returns an MObject, you need to then immediately turn around and cast that MObject into an MFnSingleIndexedComponent object (or set an an existing MFnSingleIndexedComponent to point to it).

Also, note that since the apiComponents arg to getWeights is an INPUT parameter, you will need to modify / set it BEFORE calling getWeights.

- Paul


--
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/43a71323-8b5d-4e81-b457-c19cff26fc08%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

yury nedelin

unread,
Nov 5, 2013, 2:23:00 PM11/5/13
to python_in...@googlegroups.com
Thank you Paul

It works. Awesome!

yury






Reply all
Reply to author
Forward
0 new messages