Evgeniy Zaitsev Technical Artist


Maya: isMeshHasSkinCluster()

I want to share useful function created by me, I use it in my scripts.
You can modify it in such a way that it will return a pointer to skinCluster for example. I also wrote a some comments. Hope it will be useful for someone.

import maya.OpenMaya as OpenMaya        # general Maya API module

def isMeshHasSkinCluster(m_objName):
    INPUT:  m_objName = '|group2|skinnedMesh'
            full path to kTransform object stored in scene
    RETURN: True - if m_objName has any skinCluster, False - otherwise            
    m_selectionList = OpenMaya.MSelectionList()     # create selectionList
    m_objPath = OpenMaya.MDagPath()                 # define MDagPath
        m_selectionList.add(m_objName)              # add object to selectionList
        return False
    # get first element in the selection list and connect with MDagPath
    m_selectionList.getDagPath(0, m_objPath)
    # create NULL dagIterator        
    m_dagIterator = OpenMaya.MItDag(OpenMaya.MItDag.kDepthFirst, 
    # connect dagIterator with MDagPath        
    m_dagIterator.reset(m_objPath.node(), OpenMaya.MItDag.kDepthFirst, 
    while not m_dagIterator.isDone(): # iterate
        m_objCurr = m_dagIterator.currentItem()    # current item
        if (m_objCurr.hasFn(OpenMaya.MFn.kMesh)):  # if current == kMesh
            # create MObject and connect with current item
            m_objNameMObj = OpenMaya.MObject(m_objCurr)        
            #print m_dagIterator.fullPathName() # Debug info
                # iterate in m_objNameMObj throw DependencyGraph 
                # based on kSkinClusterFilter
                m_itDG = OpenMaya.MItDependencyGraph(m_objNameMObj, 
                while not m_itDG.isDone():
                    m_currentCluster = m_itDG.currentItem()
                    m_fnSkin = OpenMayaAnim.MFnSkinCluster(m_currentCluster)
                    #print m_fnSkin.name() # Debug info
                    return True # SkinCluster exists
                return False
                #print 'No skin cluster'
        m_dagIterator.next() # next item
    return False 
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.