Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expand/Contract through Script

  • Expand/Contract through Script

    Posted by Paul Benson on December 20, 2009 at 7:16 pm

    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 &lt 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

    Paul Benson replied 16 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    December 20, 2009 at 8:49 pm

    I don’t think this answer is going to make you too happy. You can’t move a keyframe. You have to copy all its attributes and create a new one at the new time, then delete the old one. Not too tough if all your kf’s are linear or hold, gets a bit tedius if not.

    You’ll have to go through each layer recursively, property by property, looking for keyframes. Jeff Almasol’s rd-GimmePropPath script is extremely helpful in figuring out how to access any property via expressions or scripting:

    https://www.redefinery.com/ae/view.php?item=rd_GimmePropPath

    (There is a ton of good scripting info on Jeff’s site).

    Even if you master all this, you still may not be able to completely do what you want, because some properties have a custom data type, which you can’t read with a script.

    However, if you accomplish your goal (as much as possible, at least) you’ll be well on your way to understanding scripting. Good luck!

    Dan

  • Paul Benson

    December 20, 2009 at 11:13 pm

    Thanks Dan,
    at least I know I’m not missing something obvious. The rd_GimmePropPath script is a good source for the properties I may need to crawl through. It is also interesting to see different people’s coding styles. I thought this would be fairly simple…

    As for moving the keyframes, I felt the easiest method would have been to read the keyframes for a property into an array, then delete them all, and then add them back (with their adjusted time) to the same property. Then go to the next property as needed.

    However, your comment about some keyframes not being readable put some kinks into that plan…

    Maybe I’ll just ask the user to select the keyframes they want to be adjusted and copied to the other layers. Then I can use the selectedKeyframes attribute. I hate to do that, though, since I hate having code dependent upon so many user actions, and then it still may have difficulty if the user selects keyframes that I can’t read from a script.

    I’ll have to ponder.

    Thanks again,
    Pauley

  • Chris Wright

    December 21, 2009 at 8:59 pm

    script moves/nudges all Transform keyframes in all layers in all comps to the nearest exact frame for any framerate.

    https://sundstedt.se/blog/?p=661

    https://technicolorsoftware.hostzi.com/

  • Paul Benson

    December 22, 2009 at 4:44 pm

    Thanks Chris,
    it is heartening to see that others encountered the same problem I am seeing. This keyframe nudge script explicitly states each property, which was one of the options I wanted to avoid.

    It looks like I have two options:
    1) Explicitly state as many properties that I can think of (I would like to include effects). This would be a PITA and has some issues around me not handling future or third party properties.
    2) Force the user to select the keyframes they would want adjusted.

    Both techniques could fall prey to keyframes that can’t be adjusted by script.

    I think I’ll make a feature request to Adobe. How would you all prioritize these?
    1) Method to expand/contract layer (while adjusting keyframes)
    2) Method to expand/contract a group of keyframes
    3) Method to select all keyframes of a comp/layer/effect. This would allow the ability to crawl through keyframes with selectedKeyframes.
    4) Attribute for all keyframes (selected or not) in a comp/layer/effect to allow looping through all of the keyframes.

    I think #4 would be the most useful and generic.

    Pauley

  • Paul Benson

    December 22, 2009 at 5:05 pm

    I may have found something. I think I can use layer.numProperties and then the layer.Property(index) to go through the properties of a layer. Then go through the keys, using an index, to adjust as needed. That is what I was originally trying to do; maybe I had a syntax error.

    Thanks for your help, guys.

    Pauley

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy