View Full Version : Any way to toggle IK on/off for specific object?

Ryan Roye
04-27-2011, 10:42 AM
I've ran into an issue where I have more than 2 objects with IK setups and layout is getting pretty slow as a result. Previously I'd just split scenes between cuts (deleting the dormant IK object in new scene) to work around this issue but I'm in a spot where I can't do that. Is there is a way to toggle IK on/off for a specific object to help speed things up? Good animation is really hard without a snappy interface.

I'd like to avoid baking my object and using MDscan/plug is not an option in this particular case.

04-27-2011, 10:49 AM

Other than to do as ive done with my RHiggit setups which is to create scripts that disable/enable IK/MC/etc on your character specific items.

Ryan Roye
04-27-2011, 12:35 PM
Thanks for pointing me in the right direction. Fortunately I have a small bit of programming knowledge under my belt, even if 90% of that is via AutoHotKey and macro programs.

Here's the workaround I'm using... not the most robust, but it gets me by until I can muster up some time to program a more automatic solution:

In Layout:

Utilities tab > Master plugins > ADD LScriptcommander

-Open Motion Options Panel (M)
-Select the bone you want to toggle IK on/off with
-select "Keyframes" for any controllers set to "Inverse Kinematics"

In the Events tab of LScript commander, you'll notice its populated with stuff corresponding to what was done. Right click everything after "motion options" to add lines one at a time and you'll have an output as follows:

SelectItem 40000000
HController 0
PController 0
BController 0

-Save the session
-Copy all the yellow text in the LScript commander window
-New session
-Paste text. and replace the 0's with 3's (if you have a lot of bones, do search/replace with notepad)
-With some clever copy/pasting conventions, all you really need is "SelectItem", you can paste the HPB lines under each bone after you get all the selection numbers.

The script with 0's in it sets the selected bone to FK, 3's set them to IK. Execute the "sessions" as needed to toggle IK on/off. Note that the script will only be good for the specific scene you created it in. You also have to do this for every character in the scene set up with IK, so label your scripts discretely.

LScript commanded doesn't replace actual scripting knowledge, but it can help some of the less technically inclined out there.

04-28-2011, 07:49 AM
What you've got is the basic essence of it... Couple things though...

First, to TOTALLY disable the IK you also need to turn off the goal item reference for the bone/item reaching for the IK goal (turn all "IK" back to "keyframes" then open stats with w key, and you'll see that the IKchains is still the same number)

Second to take the "script" you have, which is written in command script (CS) and convert it to LScript you can simply use the convert function in the LScommander menu... this will return some errors though. SelectItem will revert to ("error"), as for some reason LW fails to convert the index number to the correct name, so you have to replace that manually... Also, you'll likely find out very quickly that the SelectItem() command doesnt work for selecting bones, so you'll want to use the SelectByName() command instead. Also remember that when using SelectByName you are selecting by explicit, case sensitive names... if you have a bone, object, light, whatever that have the exact same names, then SelectByName will pick the first one found... so make sure EVERYTHING has its own name (I use Capitalised Lower Case in all object names, and FULL CAPS in bone names for this reason).

Also, ofc, as you'll have noticed, you need 2 scritps, one to turn the IK off, and another to turn it on... you can condense this into a single script by using a conditional function to check if a certina state exists (for the purposes of switching IK the easiest is to check the Goal state of a given item)... but all that can probs come later.