Skip to content

Instantly share code, notes, and snippets.

@chris-lesage
Last active December 19, 2023 18:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chris-lesage/1ba4474789b9ad6f0933641f01f39dac to your computer and use it in GitHub Desktop.
Save chris-lesage/1ba4474789b9ad6f0933641f01f39dac 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)
@chris-lesage
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment