Created
August 16, 2017 01:14
-
-
Save EricTRocks/64e87a20129787f8c453aa071e112fe2 to your computer and use it in GitHub Desktop.
Get unused influences via OM2 and remove them using cmds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
import maya.api.OpenMaya as om2 | |
import maya.api.OpenMayaAnim as omAnim2 | |
def getSkinCluster(): | |
sel = om2.MGlobal.getActiveSelectionList() | |
shapeDagPath = sel.getDagPath(0).extendToShape() | |
shapeMeshFn = om2.MFnMesh(shapeDagPath) | |
inMeshPlug = shapeMeshFn.findPlug('inMesh', False) | |
conn = inMeshPlug.connectedTo(True, False) | |
if len(conn) < 1: | |
print "No skin cluster found on the shape node!" | |
return False | |
connPlug = conn[0] | |
connNode = connPlug.node() | |
isSkinCluster = connNode.hasFn(om2.MFn.kSkinClusterFilter) | |
skinClstr = omAnim2.MFnSkinCluster(connPlug.node()) | |
return skinClstr | |
def getUnusedInfluences(skinClstr): | |
unusedInfluences = [] | |
influenceObjs = skinClstr.influenceObjects() | |
for each in influenceObjs: | |
cmpsDagPath, weights = skinClstr.getPointsAffectedByInfluence(each) | |
if cmpsDagPath.length() == 0: | |
unusedInfluences.append(each) | |
return unusedInfluences | |
skinClstr = getSkinCluster() | |
unusedInfluences = getUnusedInfluences(skinClstr) | |
for each in unusedInfluences: | |
cmds.skinCluster(skinClstr.name(), edit=True, removeInfluence=each.fullPathName()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment