devwiki:afterfx_script

AE Programming

https://forums.creativecow.net/thread/227/18794
http://aescripts.com/templater/
https://www.premiumbeat.com/blog/10-time-saving-tips-in-after-effects/
http://www.molecularmovies.com/img/pdf_tutorials/AEbasics.pdf
https://www.themarketingtechnologist.co/creating-dynamic-videos-using-javascript-and-after-effects-the-basics/

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];
    alert(theLayer.source.file.fsName);
  • reveal layer source in project panel
    // ref: http://www.smipple.net/snippet/francoisgfx/Reveal%20Layers%20in%20Project
    var proj = app.project;
    var comp = proj.activeItem;
    if(comp){
        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
    app.beginUndoGroup(commentString);
    app.endUndoGroup(commentString);
  • current info
    app.activeViewer; // current focused viewer (comp, layer, footage panel)
  • get all item (Comp and Footage)
     
  • set expression for selected attributes
    // ref: http://www.smipple.net/snippet/francoisgfx/Set%20Expression%20to%20selected%20property%20%28in%20AE%29
    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;
                }else{
                    alert("Can't add expression to the selected property");
                };
            };
        };
    }else{
        alert("properties of an effect or a layer has to be selected");
    };
  • example
    app.project.renderQueue.items.add(myComp).applyTemplate("TemplateName");
  • since CS5 for Bridge, InDesign, InCopy, AE, Photoshop have socket object
  • devwiki/afterfx_script.txt
  • Last modified: 2021/07/20 17:55
  • by ying