Skip to content

Instantly share code, notes, and snippets.

@tpoveda
Last active June 6, 2024 06:20
Show Gist options
  • Save tpoveda/dcd2eeed9e20d7d103d6f68755eaf3b5 to your computer and use it in GitHub Desktop.
Save tpoveda/dcd2eeed9e20d7d103d6f68755eaf3b5 to your computer and use it in GitHub Desktop.
# Python version of findRelatedSkinCluster.mel
# Based in findRelatedSkinCluster.mel MEL script file found in Maya 2020
import maya.cmds
def find_related_skin_cluster(skin_obj):
skin_shape = None
skin_shape_with_path = None
hidden_shape = None
hidden_shape_with_path = None
cp_test = maya.cmds.ls(skin_obj, type='controlPoint')
if cp_test:
skin_shape = skin_obj
else:
rels = maya.cmds.listRelatives(skin_obj)
for r in rels:
skin_obj_r = '{}|{}'.format(skin_obj, r)
cp_test = maya.cmds.ls(skin_obj_r, type='controlPoint')
if not cp_test:
continue
io = maya.cmds.getAttr('{}.io'.format(skin_obj_r))
if io:
continue
visible = maya.cmds.getAttr('{}.v'.format(skin_obj_r))
if not visible:
hidden_shape = r
hidden_shape_with_path = skin_obj_r
continue
skin_shape = r
skin_shape_with_path = skin_obj_r
break
if not skin_shape:
if not hidden_shape:
return ''
else:
skin_shape = hidden_shape
skin_shape_with_path = hidden_shape_with_path
clusters = maya.cmds.ls(type='skinCluster')
for c in clusters:
geos = maya.cmds.skinCluster(c, query=True, g=True)
for geo in geos:
if geo == skin_shape or geo == skin_shape_with_path:
return c
return ''
# print(find_related_skin_cluster('pSphere1'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment