graphic:javascript:afterfx

Differences

This shows you the differences between two versions of the page.


graphic:javascript:afterfx [2021/08/22 19:45] (current) – created ying
Line 1: Line 1:
 +====== Pass Javascript to AE ======
 +
 +  * method:
 +    - File > Scripts Menu, to display scripts from scripts folder
 +    - File > Scripts > Run Script File
 +    - Window > Script with UI + Dockable inside ScriptUI folder
 +    - during command line:
 +      - afterfx -r script_file_path.jsx
 +      - afterfx -s "javascript cmds"
 +    - 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 <code javascript>
 +var myPanel = this;
 +myPanel.add("button", [10,10,100,30], "Tool #1");
 +</code>
 +  * if UI creation is inside a function, it will require passing this as reference in function parameter <code javascript>
 +function createUI(parent){
 +  var curPanel = parent;
 +  curPanel.add("button", [10,10,100,30], "Tool #1");
 +  return curPanel;
 +}
 +var myPanel = createUI(this);
 +</code>
 +
 +====== 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 <code javascript>
 +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.
 +</code>
 +====== 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 ======
 +
 +  - system
 +  - file
 +  - folder
 +  - socket
 +  - application
 +    - settings
 +    - 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 <code javascript>
 +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 
 +</code>
 +  * project panel item <code javascript>
 +// 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
 +</code>
 +  * project panel creation <code javascript>
 +var compFolder = app.project.items.addFolder("comps");
 +</code>
 +
 +**Layer Info**
 +  * get current layer <code javascript>
 +var result='';
 +if(app.project.activeItem.selectedLayers.length != 0) {
 +    result = app.project.activeItem.selectedLayers[0].name;
 +}
 +alert(result);
 +</code>
 +
 +**Text Layer Info**
 +
 +<code javascript>
 +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
 +</code>
 +
 +  * Layer property link expression <code javascript>
 +myComp = app.project.activeItem;
 +myLayers = myComp.selectedLayers;
 +myLayers[0].property("Opacity").expression='thisComp.layer("Cap 2").transform.opacity';
 +</code>
 +====== 3D Space Calculation ======
 +
 +  * 2D_null layer's position set to 3D_null <code javascript>thisComp.layer("3D_null").toComp([0,0,0]);</code>