Maya/Python: SpringIK using Python gives me different result than manual method

As the title says really. Result from this:

  import maya.cmds as mc
    selected = mc.ls(sl=True)
    
    mc.ikHandle(sj=selected[0], ee=selected[1], sol='ikSpringSolver',ap=False )

flips the joint chain.

But if I create spring solver manually, (selecting the bones/using mouse), no flipping occurs. Any ideas?

This only happens when I re-orient the original skeleton though. (Aim axis being X, and UP axis being Z)

Take a look at the order of the nodes returned in selected = mc.ls(sl=True), and perhaps reorder the items or the indices if they are backwards?

[QUOTE=btribble;28434]Take a look at the order of the nodes returned in selected = mc.ls(sl=True), and perhaps reorder the items or the indices if they are backwards?[/QUOTE]

Hmm. I’m fairly new to Python so I would really appreciate it if you could elaborate here.

I checked the list and it is in a correct order:

[u'B_L_Hip_Uppr', u'B_L_Hip_Lowr', u'B_L_Knee', u'B_L_Ankle', u'B_L_ball', u'B_L_Toes']

It seems like it happens only if the last joint selected(before creation of the IK) is ankle, ball or toes. What could be causing this bizarre behavior?

But then again, I just drew a random skeleton without reorienting the chain and tried this script = instant flip

Seems like moving the knee joint a bit forward, fixed the issue but this is hardly a solution. Why is this happening in the first place? If everything works properly using mouse and keyboard, surely Python should do as good of a job if not better…

You might try echoing all commands when you do it manually to see what it is doing from MEL and see if there is a difference between how MEL and Python operate. I have no idea why this might be happening otherwise.

[QUOTE=btribble;28446]You might try echoing all commands when you do it manually to see what it is doing from MEL and see if there is a difference between how MEL and Python operate. I have no idea why this might be happening otherwise.[/QUOTE]

Thanks for the suggestion, but since I’m a scripting newbie, I can’t make sense of echoed commands. I see some familiar lines here and there but that’s it.

I guess there’s just no way to create Spring IK’s using Python.

I know this post is rather old, but I came across the same problem recently and my workaround was to create my IK Handle using the ikRPsolver (which did not move my chain) and then change the solver using:

connectAttr(“ikSpringSolver.message”, “%s.ikSolver” %ik_handle, force = True)

Make sure you source the ikSpringSolver first for that to work.

It fixed the issue on my end, hope it can be of use to someone else in the future :slight_smile:

2 Likes

I know, reviving an old topic and the original poster has probably solved their issue long ago…but I found if I loaded the Spring IK manually (type “ikSpringSolver” into the MEL command line and press enter), then the Python command would work properly. No idea yet how to get Python to load the solver

@kimmuryiel

import pymel.core as pm
pm.loadPlugin('ikSpringSolver.mll')

On the original issue, the spring solver, and rp solver are different methods for solving ik. RP solvers are RotatePlane solver, needing guidance to know what plane to bend in. Good for Biped arms and legs. The Spring solver is for more than “one knee”, behaviors, like a dog, where you want to control the internal angle of the knee and ankle for tension, not just its arrival at the end goal.

The python vs mel implementation of the solvers is irrelevant, and doesn’t change the solver’s behavior. Any change would be a result of user error in selection order, or flags.

If you aren’t animating the preferred angle attribute of the joints, a poleVector constraint will solve the flipping.

Everytime I’ve tried to use that spring solver for what its suppose to do, I get burned somewhere else down the line with how it behaves. Mainly in that if any aspect of its controls are in the same hierarchy, its easy to get double transform behavior out of the chain.

My non spring solver solution

1 Like