Last active
December 19, 2023 18:55
-
-
Save chris-lesage/1ba4474789b9ad6f0933641f01f39dac to your computer and use it in GitHub Desktop.
Snippet to removeUnusedInfluences in Autodesk Maya using Python.
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 | |
''' | |
# 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
From this Twitter thread:
https://twitter.com/yantor3d/status/1019374353727836162