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);

3D Space Calculation

  • 2D_null layer's position set to 3D_null
    thisComp.layer("3D_null").toComp([0,0,0]);