grabbing skin cluster. API

1,789 views
Skip to first unread message

i.r.r...@gmail.com

unread,
Oct 8, 2009, 10:57:01 AM10/8/09
to python_inside_maya
if there is a way to grab a hold of information relating to mesh such
as skin clusters using API. I know in python I could simply eval the
findRelatedSkinCluster or grab all the skinClusters in the scene and
then work backwards from there. But I'm trying to work exclusively
through API at the moment and would love to find a way to start with a
selected mesh and grab information for it. thanks!!

Brandon L. Harris

Chad Vernon

unread,
Oct 8, 2009, 11:23:19 AM10/8/09
to python_in...@googlegroups.com
You'll have to traverse the DG with MItDependendencyGraph to look up its history.

Chad

Paul Molodowitch

unread,
Oct 8, 2009, 11:23:23 AM10/8/09
to python_in...@googlegroups.com
Here's the code I used to accomplish that task in PM_heatWeight:

def isATypeOf(node, type):
"""Returns true if node is of the given type, or inherits from it."""
if isinstance(node, basestring) and cmds.objExists(node):
return type in cmds.nodeType(node, inherited=True)
else:
return False

def listForNone( res ):
if res is None:
return []
return res

def getSkinClusters(mesh):
"""
Returns a list of skinClusters attached the given mesh.
"""
return [x for x in listForNone(cmds.listHistory(mesh))
if isATypeOf(x, 'skinCluster')]


Obviously, not all api, but the only call that I don't know of any
easy API conversion for is listHistory. I think in order to get an
equivalent result, you have to trace back through connections to
'inMesh' (or equivalent if you're not using a poly mesh), and check
for nodes that have their 'isHistoricallyInteresting' attribute set...
but I'm not positive.

Be interested to hear what others do for this...

- Paul

On Thu, Oct 8, 2009 at 7:57 AM, bha...@irrigger.com
<i.r.r...@gmail.com> wrote:
>

Paul Molodowitch

unread,
Oct 8, 2009, 11:57:04 AM10/8/09
to python_in...@googlegroups.com
Hmm... now I'm curious though. What ARE the parameters for something
to be considered in the history of a given node? Is it anything
that's an input, and isHistoricallyInteresting? Only historically
interesting nodes that connect to certain inputs on the end node? If
so, what inputs?

- Paul

Chad Vernon

unread,
Oct 8, 2009, 11:57:02 AM10/8/09
to python_in...@googlegroups.com


import maya.OpenMaya as OpenMaya
import maya.OpenMayaAnim as OpenMayaAnim
# oMesh is MObject to your mesh
try:
    itDG = OpenMaya.MItDependencyGraph(oMesh, OpenMaya.MFn.kSkinClusterFilter, OpenMaya.MItDependencyGraph.kUpstream)
    while not itDG.isDone():
        oCurrentItem = itDG.currentItem()
        fnSkin = OpenMayaAnim.MFnSkinCluster(oCurrentItem)

        # Don't need to loop any more since we got the skin cluster
        break

except:
    # No skin cluster
    pass

i.r.r...@gmail.com

unread,
Oct 8, 2009, 12:11:42 PM10/8/09
to python_inside_maya
Very cool. I will test this out. Hopefully you will not become annoyed
with my questions. I think after I get my head wrapped around where to
look and how to interpret the information I will at least be headed in
the right direction. Thanks again!

Brandon L. Harris
Message has been deleted

br...@meljunky.com

unread,
Oct 8, 2009, 2:15:57 PM10/8/09
to python_in...@googlegroups.com
Test each item and compare the apiType too OpenMaya.MFn.kSkinClusterFilter. The first skinCluster may not be correct. Suppose an influence is bound and the geo is not bound. The loop will find the influence's skinCluster and exit. Test the outGeometry is the same as the node you are looping before exiting.

-brian
-------- Original Message --------
Subject: [Maya-Python] Re: grabbing skin cluster. API
From: "bha...@irrigger.com" <i.r.r...@gmail.com>
Date: Thu, October 08, 2009 1:02 pm
To: python_inside_maya <python_in...@googlegroups.com>


import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
import maya.OpenMayaAnim as OpenMayaAnim
"""--------------------------------------------------------------------"""

#still don't know exactly how to take the selection into account with
API.
sel = cmds.ls(sl=True)

#declare variables as types
node = om.MObject()
selectionList = om.MSelectionList()

selectionList.add(sel[0])
selectionList.getDependNode(0,node)



# oMesh is MObject to your mesh
try:
itDG = OpenMaya.MItDependencyGraph(node,

OpenMaya.MFn.kSkinClusterFilter,
OpenMaya.MItDependencyGraph.kUpstream)
while not itDG.isDone():
oCurrentItem = itDG.currentItem()
fnSkin = OpenMayaAnim.MFnSkinCluster(oCurrentItem)

# Don't need to loop any more since we got the skin cluster
break

except:
print "no Cluster"

# No skin cluster
pass


Now this always prints "no Cluster" even if I have a skinned mesh
selected. I'm thinking that how I am getting a hold of the mesh object
is the problem, but I'm still shaky on how to get that information.



Brandon Harris

unread,
Oct 23, 2009, 2:31:38 PM10/23/09
to python_inside_maya

Reawakening the topic. I can grab ahold of the skinCluster by
traversing the plugs downstream and grabbing the skincluster. What I
am finding though is that in some cases I can grab a skin cluster that
may not be directly plugged into the shape (ie a blendshape with a
skinCluster) This doesn't happen if the selected object has a
skinCluster, but if it doesn't, but the blendshape does it will grab
the blendshapes skinCluster.


itDG = openMaya.MItDependencyGraph(shape.node
(),openMaya.MItDependencyGraph.kDownstream,openMaya.MItDependencyGraph.kPlugLevel)
while not itDG.isDone():
oCurrentItem = itDG.currentItem()
#the iterator returns an MObject that we then check to see
if it is a skinCluster. If it is, Save it.
if oCurrentItem.hasFn(openMaya.MFn.kSkinClusterFilter):
skinCluster = openAni.MFnSkinCluster(oCurrentItem)
print (skinCluster.name() + " will be returned")
break
itDG.next()


I suppose it's not a deal breaker, but I would like to ensure that the
tool won't break. Does anyone know of a way to compare plugs? Maybe
see if the skinCluster that is returns is actually connecting to the
shape?

johnvdz

unread,
Nov 13, 2009, 8:38:31 PM11/13/09
to python_in...@googlegroups.com
Hi all,

i'm trying to get the Bounding box of a prexisting mesh. but i'm not
sure if i'm aproching it the right way. has anyone dont this before? i
see some samples of setting a BBox but none for setting.

i'm new to api so i could be doing the wrong thing here eaither way it
doesnt work. any help would be great. i need to call this so i can plug
height, width, depth into another function.

cheers

john
################

import maya.OpenMaya as OpenMaya

def boundingBox():

selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selection )

dagPath = OpenMaya.MDagPath()
mObj = OpenMaya.MObject()
Bbox=OpenMaya.MBoundingBox(mObj)
print Bbox.width()
print Bbox.height()

boundingBox()
#####################

Makoto

unread,
Nov 14, 2009, 7:16:57 AM11/14/09
to python_inside_maya
You need to get dagpath from your selection first, then extend it to
the shape. And put the dagpath to MFnDagNode to get bbox infomation.

import maya.OpenMaya as OpenMaya

selectList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selectList )
dagpath = OpenMaya.MDagPath()

selectList.getDagPath(0, dagpath)
dagpath.extendToShape()
fDagNode = OpenMaya.MFnDagNode(dagpath)

bbox = fDagNode.boundingBox()
print bbox.width()
print bbox.height()

Thanks,
Makoto

johnvdz

unread,
Nov 14, 2009, 2:13:32 PM11/14/09
to python_in...@googlegroups.com
thanks makoto,

cool so i just needed the shape node.


thanks again. all these little steps take awhile to get around

cheers

john
Reply all
Reply to author
Forward
0 new messages