“components” is probably gonna be built by a subclass of MFnComponent (IIRC, it’ll be MFnSingleIndexedComponent), and will be the vertices to return weights for.
“influence” is the index of the joint for this particular skincluster that you want to return weights for. Pass the joint as an MObject to MFnSkinCluster.indexForInfluenceObject to get that index.
Thanks for all your responses, it’s been really helpful!
I have some time to play with tools this weekend so I’ll definitely give your skinning tool a go @ak_eric
I have script I’ve been testing
but If I add or remove any joints, I can’t apply the skin weight, I get an error:
RuntimeError: (kInvalidParameter): Object is incompatible with this method
I did try and check for matching influences(haven’t posted that). But what I’ve done doesn’t seem to work… the learning curve for the API is definitely steeper.
import maya.api.OpenMaya as om
import maya.api.OpenMayaAnim as oma
import re
#SHAPENAME = 'character2Shape'
#SKINCLUSTER = 'skinCluster1'
def get_parameters(SHAPENAME, SKINCLUSTER):
# get shape
mesh_path = om.MSelectionList().add(SHAPENAME).getDagPath(0)
# get skin cluster
skin_cluster = oma.MFnSkinCluster(om.MSelectionList().add(SKINCLUSTER).getDependNode(0))
# get components
inf_dags = skin_cluster.influenceObjects()
inf_index = om.MIntArray()
for x in range(len(inf_dags)):
inf_index.append(int(skin_cluster.indexForInfluenceObject(inf_dags[x])))
# get influences
component = om.MFnSingleIndexedComponent()
vertex_comp = component.create(om.MFn.kMeshVertComponent)
indices = [int(re.findall(r'\d+', vert)[-1]) for vert in mc.ls(f'{SHAPENAME}.vtx[*]', fl=1)]
component.addElements(indices)
return mesh_path, vertex_comp, inf_index, inf_dags, skin_cluster
# get skin weights
path, comp, infs, dags, sk = get_parameters('characterShape', 'skinCluster1')
weights = sk.getWeights(path, comp, infs)
# set skin weights
path2, comp2, infs2, dags2, sk2 = get_parameters('character2Shape', 'skinCluster2')
sk2.setWeights(path2, comp2, infs2, weights)