IK/FK Snap - Python Script Problem

So this is what I got so far:

import maya.cmds as cmds

import maya.OpenMaya as om

#select the joints you need

sel = cmds.ls(sl=True)

#assign selection

fkwrist = sel[0]

fkelbow = sel[1]

fkshldr = sel[2]

ikwrist = sel[3]

ikpv = sel[4]

#get position from fk

fkwRaw = cmds.xform(fkwrist, ws=True, q=True, t=True)

fkwPos = om.MVector(fkwRaw[0], fkwRaw[1], fkwRaw[2])

fkeRaw = cmds.xform(fkelbow, ws=True, q=True, t=True)

fkePos = om.MVector(fkeRaw[0], fkeRaw[1], fkeRaw[2])

fksRaw = cmds.xform(fkshldr, ws=True, q=True, t=True)

fksPos = om.MVector(fksRaw[0], fksRaw[1], fksRaw[2])


#Set position of the IK wrist ctrl

cmds.move(fkwPos.x, fkwPos.y, fkwPos.z, ikwrist)


#start figuring out pv position

#find avg (midpoint of shoulder and wrist)

midpoint = (fkwPos + fksPos) / 2

#find pv direction
pvOrigin = fkePos - midpoint

#extend that length

pvRaw = pvOrigin * 2

#position pvRaw at midpoint

pvPos = pvRaw + midpoint

#stick pv at pvPos

cmds.move(pvPos.x, pvPos.y, pvPos.z, ikpv)

Everything works except for the wrist rotation/orientation. As far as I can see the problem revolves around the fact that ik wrist offset node does not match the fk wrist offset node when i execute this script…(my offsets are the ones with rotations, controls within them are clean). I am not sure how to go about fixing that. If I can make it so that the IK wrist ctrl gets the same rotations as FK wrist ctrl at the end, the script would be perfect

Any help would be appreciated :slight_smile:

The code you posted doesn’t seem to cover rotations/orientations at all so it’s hard to see where a possible orientation mismatch might happen.

If there’s a rotational offset for the ‘zero/identity’ orientation for the IK and FK wrist control then of course this needs to be applied afterwards as well.
Otherwise you could transfer the world space matrix orientation from one to the other. :slight_smile:

Also I would recommend putting your code in a code block on the forum to ensure it keeps its formatting. It’s the hashtag (#) icon in the ‘advanced’ view for writing messages or replies.

[QUOTE=BigRoyNL;26920]The code you posted doesn’t seem to cover rotations/orientations at all so it’s hard to see where a possible orientation mismatch might happen.

If there’s a rotational offset for the ‘zero/identity’ orientation for the IK and FK wrist control then of course this needs to be applied afterwards as well.
Otherwise you could transfer the world space matrix orientation from one to the other. :slight_smile:

Also I would recommend putting your code in a code block on the forum to ensure it keeps its formatting. It’s the hashtag (#) icon in the ‘advanced’ view for writing messages or replies.[/QUOTE]

Thanks for the formatting tip.

As for the script itself, I am kind of new to this whole Python thing and although I slowly start to integrate scripting into my rigging workflow, I don’t always understand what’s actually happening between the lines. I was following a tutorial for this script but the author didn’t explain how to match orientation of the IK wrist to that of an FK wrist. I’ve been trying to figure it out using my snap and orient script but so far I’ve had no luck :confused:


fkwrist = cmds.xform(selected[0], query=True, rotation=True, worldSpace=True)
cmds.xform(selected[3], rotation=fkwrist, worldSpace=True)

For some reason, when I execute this code, nothing seems to happen. It works on simple objects I tested but it does not do anything when I select fk and IK ctrls. (My controls setup goes like this btw: offset group>sdk group>control)

Any ideas?

Okay apparently the problem was this:

sel = cmds.ls(sl=True)

Working version:

selected = cmds.ls(sl=True)