Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aigcoder/e9e534ff6102d827337e37bf57f87ae6 to your computer and use it in GitHub Desktop.

Select an option

Save aigcoder/e9e534ff6102d827337e37bf57f87ae6 to your computer and use it in GitHub Desktop.
Snippet to removeUnusedInfluences in Autodesk Maya using Python.
import maya.cmds as cmds
'''
# EXAMPLE USAGES:
# Removes all unused influences from skinCluster1
remove_unused_influences('skinCluster1')
# Removes the two specified joints from Body_SkinCluster,
but only if they are not currently weighted to anything.
remove_unused_influences('Body_SkinCluster', ['leg_L0_5_jnt', 'leg_R0_5_jnt'])
'''
def remove_unused_influences(skinCls, targetInfluences=[]):
'''
Snippet to removeUnusedInfluences in Autodesk Maya using Python.
The MEL version runs slowly, over every influence one at a time.
"targetInfluences" allows you to directly specify which influences to remove.
This will only remove targets which are not currently being used.
'''
allInfluences = cmds.skinCluster(skinCls, q=True, inf=True)
weightedInfluences = cmds.skinCluster(skinCls, q=True, wi=True)
unusedInfluences = [inf for inf in allInfluences if inf not in weightedInfluences]
if targetInfluences:
unusedInfluences = [
inf for inf in allInfluences
if inf in targetInfluences
if inf not in weightedInfluences
]
cmds.skinCluster(skinCls, e=True, removeInfluence=unusedInfluences)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment