Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Use script to retrieve value from expression

  • Use script to retrieve value from expression

    Posted by Oscar Nyquist on October 2, 2020 at 2:24 pm

    Hello,

    I’m trying to create a script that will resize my comp according to a value retrieved from an expression within the comp. First of all, is this even at all possible? If so, I would love some assistance on how this would be done, or pointers to any relevant resources.

    Many thanks in advance!

    Oscar Nyquist replied 5 years, 9 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    October 2, 2020 at 3:12 pm

    Here’s a simple example that gets the comp width from a slider control that has an expression:

    var myComp = app.project.activeItem;

    var myWidth = myComp.layer(1).property("Effects").property("Slider Control").property("Slider").valueAtTime(0,false);

    myComp.width = myWidth;

  • Oscar Nyquist

    October 2, 2020 at 9:25 pm

    Wow, this was exactly what I was looking for, and I thought it would be much more complicated. Thank you so much!

    While I have you, another possibly more difficult obstacle: would it be possible to create a solution for scaling font size with say comp width?

  • Brendon Murphy

    October 3, 2020 at 4:24 am

    You can do it dynamically with an expression on scale:

    compWidth = thisComp.width;

    compHeight = thisComp.height;

    ratioX = value[0]/1920; //replace 1920 with your original comp width

    ratioY = value[1]/1080; //replace 1920 with your original comp height

    newSizeX = compWidth*ratioX;

    newSizeY = compHeight*ratioY;

    [newSizeX,newSizeY];

    You’ll need to script out the position as well if you want the text to stick in place, or have your anchor point in the center of the comp.

  • Oscar Nyquist

    October 15, 2020 at 12:37 pm

    Apologies for the late reply.

    This solution was much more elegant than the one I came up with at first, and seems to be working perfectly together with my positioning expressions. Thank you too!

  • Brendon Murphy

    October 15, 2020 at 7:04 pm

    Hey Dan, silly question here. How do you reply with your code in a separate box? I’ve noticed the forum font does some bad things when I paste replies directly in the reply box.

  • Dan Ebberts

    October 15, 2020 at 7:33 pm

    Once you start entering text, you can click on the Aa below to expose text formatting options. Move to a new line and click the </> for preformatted text and paste your expression in the box. What I haven’t figured out is how to keep it from double spacing the lines. Maybe someone will reveal that trick…

  • Brendon Murphy

    October 15, 2020 at 8:28 pm

    great, thank you!

  • Oscar Nyquist

    October 19, 2020 at 8:16 am

    I’ve tried adding a function to the script, but this is a bit above my level so I just wanted to ask for a little more help.

    I would like the script to check for precomps with a specific name and then resize that comp to the same size as the main comp. So, let’s say, if the main comp contains a precomp named “one” and/or “two”, resize them. If they don’t exist, then do nothing.

    I understand this might be a little complicated, so any pointers in the right direction are appreciated. Thanks!

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