Finally, space switching and fk/ik snapping work using scriptJob. Mel procedures are stored in scriptNode and called by scriptJob once the file is loaded. This is the method I learned by breaking Stewart of Animation Mentor.
The trickest part is “keyable” space switching. Since I’m using scriptJob’s “attributeChange” event, if the “space” attribute is directly keyed, scrubbing the timeline will change the value and unexpectedly invoke the proc.
My solution is to move the keys to another attribute.
- Create the space switching attribute, “space”, as non-keyable and hidden.
- Create another attribute, “spaceNow”, which is keyable, driving original “space” ( as a space indicator and not to be changed directly by user ).
- Create one more attribute, “spaceSwitch”, which is non-keyable, used to change space non-pop, and used by attributeChange event.
Having attributes in single control I could key the transform and space at once. This avoids missing selection or keys if I want to adjust timing later.
By the way, you still need to use the copy and paste worldspace fix if the position of control changes before or after the switching frame.