Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using a script to add an expression to a layer?

  • Using a script to add an expression to a layer?

    Posted by John Wilkins on March 30, 2008 at 11:41 am

    I’m not sure if I’m approaching this from the right angle but I’d appreciate some feedback.

    Dan has just helped me with an expression: timeToCurrentFormat(time) which when applied to a text layer’s source property displays the frame numbers of the comp as a timecode.

    I want to include this function in a script I’ve been working on which stamps the filename, framerate, aspect ratio etc. as new text layers to a selected comp (like a slate).

    Is it possible to script an new text layer which has timeToCurrentFormat(time) as the expression for the source text property? or are scripts-scripts and expressions-expression with the two never meeting?

    Thanks for any advice you can offer

    John

    Yaavi Foxy replied 7 years, 8 months ago 8 Members · 13 Replies
  • 13 Replies
  • Filip Vandueren

    March 30, 2008 at 6:32 pm

    Hi John,

    there’s no problem in setting an expression from a script, you can for example use this in a script:

    app.project.activeItem.layer(1).text.sourceText.expression = “timeToCurrentFormat(time)”;

  • John Wilkins

    March 30, 2008 at 6:51 pm

    Thanks Filip, thats a great help!

    One quick query though, could you advise me how I could re-phrase the script to create a new layer rather than replace the (1) layer.

    Thanks for your help, I really appreciate it.

    John

  • Filip Vandueren

    March 30, 2008 at 8:10 pm

    OK,
    I’m no scripting expert but I think something like this should work:

    {
    activeComp=app.project.activeItem;

    T=activeComp.layers.addText();
    T.name = "Timecode Burn";
    T.startTime = 0;
    T.outPoint = activeComp.duration;
    T.text.sourceText.expression = "timeToCurrentFormat(time)";
    T.transform.position.setValue([100,80,0]);
    }

    Please note that you can’t set the style of the text via scripts or expressions (the Font, size, kerning, colour, etc.)
    It will use the current settings, so first make a textlayer using the style you want, delete it and then you can run the script.

  • John Wilkins

    March 30, 2008 at 9:02 pm

    Thanks great Filip – just what I needed. Thanks again!

    John

  • Ted Mihu

    June 30, 2014 at 1:55 pm

    Hello, I was wondering how I can add an expression to an Audio Amplitude null through scripting. I want to add a smooth expression to the “Both Channels” slider effect of the null.

  • Xavier Gomez

    July 1, 2014 at 1:00 pm

    app.project.activeItem.layer(1).effect("Both Channels")(1).expression = "smooth(0.2, 5, time);";

    See this: https://forums.creativecow.net/readpost/2/911517 to see how smooth works.

    Xavier

  • Ted Mihu

    July 3, 2014 at 2:11 pm

    Thank you so much!!

    Any chance you know how to access the anchor point of a layer in script? I can’t find any help online, and since it’s two words, I’m having trouble.

  • Dan Ebberts

    July 3, 2014 at 4:15 pm

    Try this:

    app.project.activeItem.layer(1).property(“Anchor Point”).setValue([0,0])

    Dan

  • Dave Jackson

    June 29, 2016 at 7:34 am

    I know this is years later and its annoying to keep adding to an old thread but it’s along the same lines:

    How would you target a selected property to add the expression to, in order to make it more versatile?

    this works:
    app.project.activeItem.layer(1).property(“Position”).expression = “wiggle(2,2)”;

    but this would be more useful, and doesn’t:
    app.project.activeItem.selectedLayers.property.expression = “wiggle(2,2)”;

    cheers

  • Dan Ebberts

    June 29, 2016 at 4:32 pm

    I guess I’d do something like this:


    props = app.project.activeItem.selectedProperties;
    for (var i = 0; i < props.length; i++){
    if (props[i].canSetExpression){
    props[i].expression = "wiggle(2,2)";
    }
    }

    Dan

Page 1 of 2

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