To go from IK to FK is simple: just store the transforms of the objects in the chain from base to tip, switch the enabled state to 0, and set the objects to match the stored transforms (starting at the base and working toward the tip).
To go from FK to IK basically comes down to having a dummy object to match the IK control position to, and using a swivel target to control the angle of the limb. Again fairly simple... as long as you have a chain with a single joint!
Here's a simple chain with 3 segments and a tip. In the first panel, the IK control object's enabled state is 0. If I set the enabled state to 1 via Maxscript (or click the "enabled" checkbutton with "auto snap" unchecked), then I get the second panel. If I first click "ik/fk snap" then do either, the IK enabled state switches to 1, but the bones remain in place.
My solution for 2-segment IK chains does not work. The IK control and swivel target positions are exactly where they should be, but with more than 2 segments, that is not enough to match the bones to their FK state transforms.
The macro recorder shows
which works in a script if the IK control object in question is selected. And that seems to be the only part that's necessary; the macro recorder also shows all the preferred rotations within the chain, but whether those values are set or not appears to have no effect on anything.
Unfortunately, I've been totally unable to figure out what the snap button/action is actually DOING. I can't find any values anywhere that it actually seems to be changing, beyond the actual transformations of the objects in the IK chain (which, with the chain in an IK state, I cannot find any other way to set directly...)
I suppose if I absolutely have to I can always have my script automatically select the IK control object in question and run "IKChainControl.IKChainActions.snap ()", but there HAS to be a better way, doesn't there??