AE Programming

AE Expression

  • position wiggle
    fps=5; //frequency
    amount=8;  //amplitude
    wiggle(fps,amount,octaves = 1, amp_mult = 0.5,(Math.round(time*fps))/fps);

AE Scripts

  • run from cmd to call a javascript (your may or may not need full path)
    afterfx.exe -s "var myArg="I'm a string!"; $.evalFile("Your path to script here")"
    c:\PathToAE\AfterFX.exe -r C:\"path"\"script name".jsx 

AE Common code

Details on Javascript UI, can refer to my Photoshop javascript study: scriptUI in detail

ScriptUI vs Dockable ScriptUI in AfterEffects

  • In general Adobe application, scriptUI are only 2 types: Pallete, Dialog; But in AfterEffects, there are 3 types: Dockable Pallete, non-dock normal Pallete, Dialog
  • for ScriptUI pallete to become dockable window, it needs
    1. code written in certain format way
    2. code file need to be in ScriptUI folder in application folder, and it opened from Windows menu

ScriptUI dockable code

  • show project file in explorer
    app.executeCommand(app.findMenuCommandId("Reveal in Explorer"));
  • show layer file path
    var theLayer = app.project.activeItem.selectedLayers[0];
  • reveal layer source in project panel
    // ref:
    var proj = app.project;
    var comp = proj.activeItem;
        var selectedLayers = comp.selectedLayers;
        if(selectedLayers.length > 0){
            for(var l = 0 ; l < selectedLayers.length ; l++){
                selectedLayers[l].source.selected = true;
  • write to info panel as output
    write('info here'); writeln('info breakline');
  • app interaction
    app.activate(); // bring to front
    app.beginSuppressDialogs(); // no error pop-up; endSuppressDialogs
    // make undo group
  • current info
    app.activeViewer; // current focused viewer (comp, layer, footage panel)
  • get all item (Comp and Footage)
  • set expression for selected attributes
    // ref:
    var link_expression = 'wiggle(10,30);'
    var cur_comp = app.project.activeItem; // our current selected & opened comp
    if(cur_comp && cur_comp.selectedLayers[0].selectedProperties[0]){ // if a comp and at least one property is selected
        for(var i = 0 ; i < cur_comp.selectedLayers.length; i++){ // go trough each selected layers
            var cur_layer = cur_comp.selectedLayers[i];
            for(var j = 0 ; j < cur_layer.selectedProperties.length; j++){ // go through each selected properties
                var cur_attr = cur_layer.selectedProperties[j];
                if(cur_attr.canSetExpression) {
                    cur_attr.expression = link_expression;
                    alert("Can't add expression to the selected property");
        alert("properties of an effect or a layer has to be selected");
  • example
  • since CS5 for Bridge, InDesign, InCopy, AE, Photoshop have socket object
  • devwiki/afterfx_script.txt
  • Last modified: 2021/07/20 17:55
  • by ying