Using python to create a bindSkin in Maya

5.4k Views Asked by At

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.

3

There are 3 best solutions below

3
On BEST ANSWER

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)

0
On

I was using the wrong command. mc.skinCluster is what I wanted to use, not mc.bindSkin.

0
On

cmds.bindSkin() command made for binding bones to geometry. It's not suitable for binding to IK's only. So you need to assign what joint you need to bind to.

For example:

import maya.cmds as mc

mc.select('ikHandle1','nurbsCircle1','joint5')
mc.bindSkin('ikHandle1','nurbsCircle1','joint5')

# the order of selection is vital

For constraining selected objects use the commands like this:

mc.pointConstraint('ikHandle1','nurbsCircle1', weight=5.0)

To find out what constraints are available to you, use Rigging moduleConstrain menuParent, Point, Orient, Scale, Aim, Pole Vector.