Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Creating and Editing Expression Controls using Scripts

  • Creating and Editing Expression Controls using Scripts

    Posted by Rutger on September 24, 2006 at 8:56 pm

    Hello,

    I am fairly new to using Scripts in After Effects, but after browsing the After Effects Scripting guide (from Adobe) and searching both Dan Ebberts Motion Script page as well as the AE Enhancers page, I was unsuccesful in finding help on defining/editing the properties of expression controls using scripts.

    I would like to write a script that creates a controlable sine-wave motion to the position of a layer in a comp. I would like to use slider controls to define the amplitude, frequency etc. of the sine wave. I have already created the slider controls using the

    myLayer.Effect.addProperty(“ADBE Slider Control”) command.

    I have also set up the sinewave expression for the position property with fixed values:

    something to this effect:

    myLayer.property(“position”).expression = “x = 500* Math.cos……etc”

    Now, of course I would like the fixed value of 500 to be replaced by the value of my slider control. How do I program that?

    I hope that my questions are clear, and I would appreciate any help on this.

    Regards,

    Rutger

    Nicholas Petersen replied 12 years, 11 months ago 4 Members · 6 Replies
  • 6 Replies
  • Brian Charles

    September 24, 2006 at 11:25 pm

    Assuming you want to control the y position using an expression.

    Add 2 slider controls to the layer.

    Name the first Frequency and the second Amplitude.

    You can pick whip the values to the sliders or use the expression below.

    Add this expression to the position property of the layer:

    x = transform.position[0];
    y = effect(“Amplitude”)(“Slider”)*Math.sine(effect(“Frequency”)(“Slider”)*time);
    [x,y]

    Now you can keyframe the sliders to control the amplitude and frequency.

  • Rutger

    September 24, 2006 at 11:38 pm

    Thanks for the suggestion, but that is not what I meant. I want to use scripts to set this up automatically. In other words: I select a layer, run the script and After Effects generates the slider controls and ‘pick wips’ them automatically and enters the proper expressions. This way, I can use this effect over and over again, and set this up in seconds in any project regardsless of what I am working on.

    Any other suggestions are welcome.

    Rutger

  • Dan Ebberts

    September 25, 2006 at 12:35 am

    You have to build the text for the expression. Something like this:

    
    var myEffect = myLayer.Effect.addProperty("ADBE Slider Control");
    var myExpr = "amp = effect(1)("Slider");" + "\r" +
                 "freq = effect(2)("Slider");" + "\r" +
                 "x =    ... etc.           ;";
    
    myLayer.property("position").expression = myExpr;
    

    Sorry – I haven’t tested it but it should give you the idea.

    Dan

  • Rutger

    September 26, 2006 at 1:51 am

    Thanks Dan,

    It is working now, and I also was able to rename the sliders by using the

    myLayer.effect(1).name = “Amplitude” command so that all the sliders are properly labeled and organized.

    By the way, now that I have your attention, I read in the After Effects Scripting Guide that there is no method built in After Effects that can record a series of actions and convert them into script. Do you know of any 3rd party plugins that would do this? It would essentially be a ‘macro’ recorder, as you see for instance in Visual Basic for Excel. I think such tool could be very handy for more entry level users that want to take advantage of scripting. But it may simply not exist.

    Thanks again,

    Rutger

  • Dan Ebberts

    September 28, 2006 at 4:51 am

    I’m not aware of any such tool. Sorry.

    Dan

  • Nicholas Petersen

    May 24, 2013 at 1:06 pm

    I’m curious about editing expression controls, but more so how to change their name. Here’s where I’m stuck…

    app.project.activeItem.layer(4).effect.addProperty(“Slider Control”);
    app.project.activeItem.layer(4).effect.(“Slider Control”).name = “Raise/Lower Arm”;

    I’ve been pawing through the scripting guide, but I have not been able to find anything about changing an expressions name. I tried this, thinking that it might work, and obviously it didn’t. I got the following error message:

    “Function (predicate expression) cannot work with this class””

    What do I need to do to change the name of an expression control?

    Thanks!

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