Toggle interpolation script?
Moderators: Víctor Paredes, Belgarath, slowtiger
Toggle interpolation script?
How difficult would it be to make a script that toggles the interpolation type for all keyframes (angle, transform, scale) on a bone layer?
I'm thinking of the following:
- Toggle between "step" and "smooth" for all angle, transform and scale keyframes on currently selected bone layer
- Have the script available as a button. Me no like having to look around in the script menu.
Lua doesn't look like too difficult a language to learn. But it's the jump from general Lua knowledge to Moho specific Lua scripts that looks like the difficult one.
I'm thinking of the following:
- Toggle between "step" and "smooth" for all angle, transform and scale keyframes on currently selected bone layer
- Have the script available as a button. Me no like having to look around in the script menu.
Lua doesn't look like too difficult a language to learn. But it's the jump from general Lua knowledge to Moho specific Lua scripts that looks like the difficult one.
It is possible. I'm trying to do this with a save bone animation script. The HUGE problem is that there is NO script access for the key interpolation. None, zippo, zero, nadda. The only way to get that information is by reading the file format which is... something you might not want to do during "production".
For instance if you are working on a file and use this button or toggle tool and you haven't saved for a while, the key interpolation might be different in the SAVED file (which is what would be read in) as apposed to the working file you haven't saved yet.
If the file is very large you have to parse the whole thing to find those keys. Granted, text parsing is pretty darn fast but even so a large file could potentially slow things down if you use this a lot. I suppose it could be done, it just makes me nervous reading the file format for something like this.
The good news is that once you get the key frame interpolation from the file format you can use the script interface to set it. So you are only reading the file, you don't have to write to it in the same way.
-vern
For instance if you are working on a file and use this button or toggle tool and you haven't saved for a while, the key interpolation might be different in the SAVED file (which is what would be read in) as apposed to the working file you haven't saved yet.
If the file is very large you have to parse the whole thing to find those keys. Granted, text parsing is pretty darn fast but even so a large file could potentially slow things down if you use this a lot. I suppose it could be done, it just makes me nervous reading the file format for something like this.
The good news is that once you get the key frame interpolation from the file format you can use the script interface to set it. So you are only reading the file, you don't have to write to it in the same way.
-vern
Yes absolutely. How silly of me. A toggle. Yes, no need to read the file format. If you know all the keys are "smooth" you can click and and make them step, linear, whatever.Manu wrote:I see, you can't read the current interpolation type for a given keyframe. That's a bit of a weird oversight.
But you could make a script that sets the interpolation for all keyframes to "Step" and another script that sets the interpolation type to "Smooth", right?
However there is no way to know what the key frames are before you press the toggle, AND you wouldn't be able to press the toggle before adding the key frame. Key frame interpolation can only be set "after the fact" or after the keys already exist.
-vern
Well, the scenario I'm thinking of is this:
1. Leave the default interpolation type on "step"
2. Block out animations with step interpolation
3. Once you're happy with the blocked-out animation, switch to "Smooth"
4. Switch back and forth between "step" and "smooth" by activating the respective scripts. You can tell from the way the keyframes look if it's currently set to "step" or "smooth"
1. Leave the default interpolation type on "step"
2. Block out animations with step interpolation
3. Once you're happy with the blocked-out animation, switch to "Smooth"
4. Switch back and forth between "step" and "smooth" by activating the respective scripts. You can tell from the way the keyframes look if it's currently set to "step" or "smooth"
Another problem is the "default" key interpolation. The default is always smooth and there is no way to change that, it's part of the application.
However you got me thinking again. What we really need is a modification to the drawing and/or bone tools. This modification would add a menu or check boxes for the different interpolation types as the tool options.
When you check the box all keys created with that tool would change to that interpolation. The current tool set does not set key frame interpolation. It just sticks in a default key which is always smooth. However, the tool itself could DEFINE SPECIFICALLY which key is placed.
EDIT: So this tool modification might have a key to hold down when moving bones or points. That key modifier would tell the script which interpolation to use. There would be no way to do it "after the fact" without right clicking on the key and changing it the way it works now. AS does not "know" when keys are selected in the timeline. Scripting has no access tot that information.
When no interpolation is defined by a script it always defaults to smooth.
So you would set keys as step. Then at the end you could select all the keys and change them to smooth, or use the "toggle". Changing all key interpolations for a bunch of channels is so easy I haven't seen a need for a special tool but I suppose it could be done.
Another issue to deal with are action reference keys. The keys inserted in the timeline when you choose to insert an action REFERENCE and not the "real" keys. Action keys are a type of key interpolation. At least that's how it works in the file format ONLY. There is no definition in the script interface for action reference key frames. The only reason I know what they are is that I deduced it by reading the file format and comparing it to the list in the script reference. So you might be able to set the key frame for this type of thing but it's not documented... at all.
-vern
However you got me thinking again. What we really need is a modification to the drawing and/or bone tools. This modification would add a menu or check boxes for the different interpolation types as the tool options.
When you check the box all keys created with that tool would change to that interpolation. The current tool set does not set key frame interpolation. It just sticks in a default key which is always smooth. However, the tool itself could DEFINE SPECIFICALLY which key is placed.
EDIT: So this tool modification might have a key to hold down when moving bones or points. That key modifier would tell the script which interpolation to use. There would be no way to do it "after the fact" without right clicking on the key and changing it the way it works now. AS does not "know" when keys are selected in the timeline. Scripting has no access tot that information.
When no interpolation is defined by a script it always defaults to smooth.
So you would set keys as step. Then at the end you could select all the keys and change them to smooth, or use the "toggle". Changing all key interpolations for a bunch of channels is so easy I haven't seen a need for a special tool but I suppose it could be done.
Another issue to deal with are action reference keys. The keys inserted in the timeline when you choose to insert an action REFERENCE and not the "real" keys. Action keys are a type of key interpolation. At least that's how it works in the file format ONLY. There is no definition in the script interface for action reference key frames. The only reason I know what they are is that I deduced it by reading the file format and comparing it to the list in the script reference. So you might be able to set the key frame for this type of thing but it's not documented... at all.
-vern
Really? I just changed it the other day and so far, when I start up AS, it keeps defaulting to "step". You can find the default interpolation settings under the "Settings.." button on the timeline.heyvern wrote:Another problem is the "default" key interpolation. The default is always smooth and there is no way to change that, it's part of the application.