-
Expand/Contract through Script
Hi all,
I am learning scripting and came up with what I thought would be a good ‘proof of concept’ as I learn the ropes, but I am hitting an issue with one of my goals.
My overall goal is to expand/contract some layers to be within a specific time frame. While generally this is for pictures (such as a slide show) I would allow video based layers to be adjusted as well. For this discussion, let’s just stick with pictures, since they can be any length.
I know how to change the start/end and in/out points. But, let’s say there are some keyframes with the layer. If the layer is originally 1 second long, and my script wants to change it to 2 seconds, I would want to move all of the keyframes and stretch them out, too; much like when you expand/contract groups of keyframes while holding the alt-key.Ideally, there would have been a expand_contract_keyframes method for the layer, but, that does not seem to exist. If you know of a method that emulates the adjusting of keyframes while holding the alt-key, please let me know.
Then I figured I would have to go through all of the keyframes and adjust them individually. Something like this:
var theProperties = activeItem.Properties; //note: 'Properties' is not a truly defined attribute
for (var i in theProperties) {
for (var lcv=1; lcv < i.numKeys(); lcv++) {
i.keytime(lcv) *= scalefactor;
}
}I realize I’d have to be a bit more careful to avoid going into an endless loop, but you get the idea, I hope. The problem is, I can’t figure out how to get all of the keyframes. The closest I have found are the selectedProperties and the selectedKeys attributes, but I don’t want to limit my calculations to just the selected properties or keys. I want an attribute as I showed above, ‘Properties’, but that does not exist.
I then thought there may be a method to ‘select all’ keyframes in a layer, so that I could then use the selectedProperties and selectedKeys attributes, but that does not seem to exist, either.
I could go through every property (opacity, then scale, then…), but that would be arduous, and would be impossible as I would not know what to call all the third party plug in properties.
Any ideas?
To recap:
First – I would just want a simple method to expand/contract the layer while adjusting the keyframes at the same time.If that does not exist, I need a way to loop through all of the keyframes (not just the selected ones) of each item.
I’m not looking for code, but any pointers on how to achieve this.
Thanks,
Pauley