import json
import maya.cmds as mc
def copy_bind_from_ng_file(file):
""" Copies skinCluster from ngSkinTools JSON file to make the same skinCluster before importing weights.
Args:
file (str): file...
Returns [str]: list of influences that we used to build the skinCluster
Usage:
copy_bind_from_ng_file('path_to_your_ng_skin_tools_weights_file.json')
"""
influences = []
missing_influences = []
with open(file) as f:
data = f.read()
json_data = json.loads(data)
f.close()
for value in json_data['influences']:
influence = json_data['influences'][value]['path'].split('|')[-1]
if mc.objExists(influence):
influences.append(influence)
else:
missing_influences.append(influence)
if missing_influences:
print 'Missing Influences from your file: \n{}'.format(missing_influences)
result = cmds.confirmDialog(b=['OK','CANCEL'], m='You have %d missing influences...continue adding skin cluster from file with %d influences?' % (len(missing_influences), len(influences)))
if result == 'OK':
mc.skinCluster(influences,
mc.ls(sl=True)[0], tsb=True)
return influences