graphic:javascript:afterfx

Pass Javascript to AE

  • method:
    1. File > Scripts Menu, to display scripts from scripts folder
    2. File > Scripts > Run Script File
    3. Window > Script with UI + Dockable inside ScriptUI folder
    4. during command line:
      1. afterfx -r script_file_path.jsx
      2. afterfx -s “javascript cmds”
    5. configure file script in Scripts Folder / Startup Folder (after UI open) + Shutdown Folder (before UI close), auto run all in order
  • stop script by press Esc or Cmd+.

ScriptUI Script Structure

I mean: those from Window Menu > Script Window ones

  • for UI + dockable script, the AE will refer the panel as “this” inside the script
    var myPanel = this;
    myPanel.add("button", [10,10,100,30], "Tool #1");
  • if UI creation is inside a function, it will require passing this as reference in function parameter
    function createUI(parent){
      var curPanel = parent;
      curPanel.add("button", [10,10,100,30], "Tool #1");
      return curPanel;
    }
    var myPanel = createUI(this);

Normal UI Script Structure

I mean: File menu > Scripts > Script Window ones

  • note “this” won't refer to anything by default unlike those from Window menu, thus, to make the script compatible in either location (File menu or Window menu), you need to check whether AE treat it as a “dockable Panel” or a “simple tool window”;
  • detection code as
    function createUI(parent){
      var curPanel = (parent instanceof Panel) ? parent : new Window("palette", "Title Here", [100,100,300,300]);
      curPanel.add("button", [10,10,100,30], "Tool #1");
      return curPanel;
    }
    var myPanel = createUI(this); // so this may be a Panel from Window menu or None from File menu.

Develop AE in Javascript

to do

file brower like Piper
parent Zero parentConstraint, then zero all Archove,Position,Rotation,Scale
instance spacer instance and push back a step

AE Object Model

  1. system
  2. file
  3. folder
  4. socket
  5. application
    1. settings
    2. project

Project

  • renderQueue
    • renderQueueItem(s) > outputModule(s)
  • item(s)
    • folderItem
    • compItem
      • layer(s) > properties
      • proxySource
    • footageItem
      • mainSource / proxySource

Source

  • solidSource > color
  • placeHolderSource
  • fileSource > file

Read AE Info

Project Info

  • project detail
    projFilePath = app.project.file; //result: /d/Projects/AE_Test/test_v001.aep
    projFileName = File.decode(app.project.file.name); // test_v001.aep 
     
    projBitDepth = app.project.bitsPerChannel; // 8
     
    projItemTotal = app.project.numItems; // total items count in project panel, the whole hierarchy 
  • project panel item
    // note: the app.project.item(index) use index from 1
    cur_item = app.project.item(1);
    alert(cur_item.selected); // query active status
    alert(cur_itemName.name); // name in panel
    alert(cur_itemName.comment); // name in panel
    alert(cur_itemName.id); // unique ref int in panel
    alert(cur_itemName.typeName); // "Footage", "Folder", "Composition"
    cur_item.remove(); // delete itself
  • project panel creation
    var compFolder = app.project.items.addFolder("comps");

Layer Info

  • get current layer
    var result='';
    if(app.project.activeItem.selectedLayers.length != 0) {
        result = app.project.activeItem.selectedLayers[0].name;
    }
    alert(result);

Text Layer Info

var result='';
if(app.project.activeItem.selectedLayers.length != 0) {
    layerName = app.project.activeItem.selectedLayers[0].name;
    textProp = app.project.activeItem.selectedLayers[0].property("Source Text");
    textDocument = textProp.value;
    result =textDocument.font; // get font name
    //textDocument.font = "Arial"; // set
    //textDocument.fontStyle = "Bold";
    //textDocument.fontSize = 36;
}
alert(result ); 
// ref: https://www.aenhancers.com/viewtopic.php?t=3084
  • Layer property link expression
    myComp = app.project.activeItem;
    myLayers = myComp.selectedLayers;
    myLayers[0].property("Opacity").expression='thisComp.layer("Cap 2").transform.opacity';

3D Space Calculation

  • 2D_null layer's position set to 3D_null
    thisComp.layer("3D_null").toComp([0,0,0]);
  • graphic/javascript/afterfx.txt
  • Last modified: 2021/08/22 19:45
  • by ying