Search code examples
pythonmayaskinning

Using python to create a bindSkin in Maya


I am trying to create a script that would help me automate the creation of a spine rig, but I am running into a problem. I am following the tutorial provided here and I am working on the step where you skin the curve to the IK joints.

However, when I try to use mc.bindSkin(), I keep getting an error:

Error: RuntimeError: file[directory]/maya/2016.5/scripts\createRigSpine.py line 200: Maya command error)

It's too late right now to for me to do much experimenting, but I was hoping someone could help me, or tell me if I'm using the wrong commands.

mc.select(crvSpine, jntIkMidSpine, jntIkChest)
mc.bindSkin(crvSpine, jntIkMidSpine, jntIkChest, tsb=True)

(have also tried mc.bindSkin() and mc.bindSkin(tsb=True))

Ideally, I want the settings to be:

Bind To: Selected Joints
Bind Method: Closest Distance
Skinning Method: Classic Linear
Normalize Weights: Interactive

Edit: I wanted to use skinCluster, not bindSkin.


Solution

  • you should use the skinCluster command to bind your curve to the joints - and you can actually do it without selecting anything!

    Try this:

    import maya.cmds as mc
    
    influences = [jntIkMidSpine, jntIkChest]
    scls = mc.skinCluster(influences, crvSpine, name='spine_skinCluster', toSelectedBones=True, bindMethod=0, skinMethod=0, normalizeWeights=1)[0]
    
    # alternatively, if you don't want such a long line of code:
    #
    influences = [jntIkMidSpine, jntIkChest]
    kwargs = {
        'name': 'spine_skinCluster',  # or whatever you want to call it...
        'toSelectedBones': True,
        'bindMethod': 0,
        'skinMethod': 0,
        'normalizeWeights': 1
    }
    scls = mc.skinCluster(influences, crvSpine, **kwargs)[0]
    
    # OR just use the short names for the kwargs...
    #
    influences = [jntIkMidSpine, jntIkChest]
    scls = mc.skinCluster(influences, crvSpine, n='spine_skinCluster', tsb=True, bm=0, sm=0, nw=1)[0]
    

    If you wanted to, you could also explicitly set the weights you want for each cv of the curve. You could use the skinPercent command, or even just use setAttr for the various weight attrs in the skinCluster (that's a little more difficult, but not much)