├── Change All Comp BG.jsx ├── Extension-Important-Directories.markdown ├── README.md ├── ScriptUI ├── ScriptUI Reference.jsx └── ScriptUI Resource String Reference.jsx ├── colorConversion.jsx ├── colorPicker.jsx └── convertToBinary.jsx /Change All Comp BG.jsx: -------------------------------------------------------------------------------- 1 | // Loops through and changes all the composition backgrounds in the project to selected color from native OS colorpicker. 2 | function setAllCompBG(){ 3 | var color = hexToAEColor($.colorPicker()); 4 | for (var i = 1; i <= app.project.numItems; i++){ 5 | if (app.project.item(i) instanceof CompItem){ 6 | app.project.item(i).bgColor = color; 7 | } 8 | } 9 | function hexToAEColor(hex){ 10 | var r = hex >> 16;var g = hex >> 8 & 0xFF;var b = hex & 0xFF; 11 | return [r/255,g/255,b/255]; 12 | } 13 | } 14 | setAllCompBG(); 15 | -------------------------------------------------------------------------------- /Extension-Important-Directories.markdown: -------------------------------------------------------------------------------- 1 | ## Extensions Directory 2 | 3 | Revision of Kamil Khadeyev's list 4 | #### CC 2014 / 2015: 5 | Mac: 6 | ``` 7 | ~/Library/Application Support/Adobe/CEP/extensions` 8 | ``` 9 | 10 | Win (system): 11 | ``` 12 | C:\Program Files (x86)\Common Files\Adobe\CEP\extensions 13 | ``` 14 | 15 | Win (user): 16 | ``` 17 | C:\Users\[ USER ]\AppData\Roaming\Adobe\CEP\extensions 18 | ``` 19 | 20 | #### CC: 21 | Mac: 22 | ``` 23 | ~/Library/Application Support/Adobe/CEPServiceManager4/extensions 24 | ``` 25 | 26 | Win (system): 27 | ``` 28 | C:\Program Files (x86)\Common Files\Adobe\CEPServiceManager4\extensions 29 | ``` 30 | 31 | Win (user): 32 | ``` 33 | C:\Users\[ USER ]\AppData\Roaming\Adobe\CEPServiceManager4\extensions 34 | ``` 35 | 36 | ## LocalStorage location 37 | Mac: 38 | ``` 39 | ~/Library/Caches/CSXS/cep_cache/ 40 | ``` 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AfterEffects-ExtendScript 2 | Snippets of useful ExtendScript code that can be used in some other Adobe host applications aside from After Effects. 3 | -------------------------------------------------------------------------------- /ScriptUI/ScriptUI Reference.jsx: -------------------------------------------------------------------------------- 1 | (function(thisObj) { 2 | 3 | scriptBuildUI(thisObj) 4 | 5 | function scriptBuildUI(thisObj) { 6 | var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "ScriptUI Template", undefined); 7 | win.spacing = 5; 8 | 9 | var groupOne = win.add("group", undefined, "GroupOne"); 10 | groupOne.orientation = "column"; 11 | groupOne.add("button", undefined, "Button"); 12 | var checkbox = groupOne.add("checkbox", undefined, "CheckBox"); 13 | checkbox.value = true; 14 | groupOne.add("radiobutton", undefined, "RadioButton"); 15 | var dd = groupOne.add("dropdownlist", undefined, ["Item 1", "Item 2", "Item 3"]); 16 | dd.selection = 2; 17 | var pb = groupOne.add("progressbar", undefined, "ProgressBar"); 18 | pb.value = 50; 19 | 20 | 21 | var groupTwo = win.add("group", undefined, "GroupTwo"); 22 | groupTwo.orientation = "column"; 23 | //groupTwo.add("iconbutton", undefined, "~/Desktop/Alert.png", "IconButton"); 24 | //groupTwo.add("image", undefined, "~/Desktop/Alert.png"); 25 | groupTwo.add("statictext", undefined, "Custom text"); 26 | groupTwo.add("edittext", undefined, "Default text"); 27 | var s = groupTwo.add("slider", undefined, "Slider"); 28 | s.value = 60; 29 | groupTwo.add("scrollbar", undefined, "Scrollbar"); 30 | 31 | 32 | var panelOne = win.add("panel", undefined, "My panel"); 33 | panelOne.add("button", undefined, "Button 1"); 34 | panelOne.add("button", undefined, "Button 2"); 35 | panelOne.add("button", undefined, "Button 3"); 36 | panelOne.add("button", undefined, "Button 4"); 37 | 38 | 39 | var myTab = win.add("tabbedpanel", undefined, ""); 40 | var tabContent1 = myTab.add("tab", undefined, "Tab1"); 41 | tabContent1.add("button", undefined, "Button 1"); 42 | var tabContent2 = myTab.add("tab", undefined, "Tab2"); 43 | tabContent2.add("button", undefined, "Button 2"); 44 | var tabContent3 = myTab.add("tab", undefined, "Tab3"); 45 | tabContent3.add("button", undefined, "Button 3"); 46 | 47 | 48 | var groupThree = win.add("group", undefined, "GroupThree"); 49 | groupThree.orientation = "column"; 50 | groupThree.add("listbox", undefined, ["Item 1", "Item 2", "Item 3"]); 51 | var myMultiColumnList = groupThree.add("listbox", undefined, "My Listbox",{ 52 | numberOfColumns: 3, 53 | showHeaders: true, 54 | columnTitles: ["Column 1", "Column 2", "Column 3"] 55 | }); 56 | var myItems = myMultiColumnList.add("item", "Item 1"); 57 | myItems.subItems[0].text = "Item 2"; 58 | myItems.subItems[1].text = "Item 3"; 59 | 60 | 61 | var groupFour = win.add("group", undefined, "GroupFour"); 62 | groupFour.orientation = "column"; 63 | var myTree = groupFour.add("treeview", undefined, ["Item 1", "Item 2", "Item 3"], "MyTreeView"); 64 | 65 | var myMultiTree = groupFour.add("treeview", [0, 0, 200, 75], "My Tree View"); 66 | var myTreeItems = myMultiTree.add("node", "Item 1"); 67 | var myNode = myTreeItems.add("node", "Item 2"); 68 | myNode.add("item", "Item 3"); 69 | 70 | win.onResizing = win.onResize = function() { 71 | this.layout.resize(); 72 | }; 73 | 74 | win instanceof Window 75 | ? (win.center(), win.show()) : (win.layout.layout(true), win.layout.resize()); 76 | } 77 | 78 | 79 | })(this); 80 | -------------------------------------------------------------------------------- /ScriptUI/ScriptUI Resource String Reference.jsx: -------------------------------------------------------------------------------- 1 | // Reference script to create palette with resource string elements 2 | // Provided by CreativeDojo.net 3 | 4 | { 5 | function myScript(thisObj) { 6 | function myScript_buildUI(thisObj) { 7 | var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Panel Name", [0, 0, 300, 300]); 8 | 9 | res = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\ 10 | myGroup: Group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\ 11 | myStaticText: StaticText{text:'StaticText Text'},\ 12 | myEditText: EditText{text:'EditText text'},\ 13 | myButton: Button{text:'Button Text'},\ 14 | },\ 15 | myPanel: Panel{text:'Panel Name', orientation:'row', alignChildren:['left', 'fill'],\ 16 | myCheckbox: Checkbox{text:'Checkbox Text'},\ 17 | myRadioButton: RadioButton{text:'RadioButton Text'},\ 18 | mySlider: Slider{value:50,minvalue:0, maxvalue:75},\ 19 | },\ 20 | myDropDownList: DropDownList{properties:{items:['Item 1', 'Item 2', 'Item 3', 'Item 4']}},\ 21 | myProgressBar: Progressbar{text:'Progressbar Text', minvalue:0, maxvalue:100, value:25},\ 22 | myListBox: ListBox{properties:{items:['Item 1', 'Item 2', 'Item 3', 'Item 4']}},\ 23 | myTabbedPanel: Panel{type:'tabbedpanel', orientation:'left', alignChildren:['left', 'fill'],\ 24 | myTab1: Panel{type:'tab', text:'Tab 1', orientation:'column', alignChildren:['left', 'center'],\ 25 | tabStaticText: StaticText{text:'This is tab 1'},\ 26 | tabButton1: Button{text:'Button Text'},\ 27 | },\ 28 | myTab2: Panel{type:'tab', text:'Tab 2', orientation:'column', alignChildren:['left', 'center'],\ 29 | tabStaticText: StaticText{text:'This is tab 2'},\ 30 | tabButton2: Button{text:'Button Text'},\ 31 | },\ 32 | },\ 33 | }" 34 | 35 | // Adds resource string to panel 36 | myPanel.grp = myPanel.add(res); 37 | 38 | // DropDownList default selection 39 | myPanel.grp.myDropDownList.selection = 2; /// Dropdown index starts at 0 40 | 41 | // Assign function to UI elements 42 | 43 | 44 | // Setup panel sizing and make panel resizable 45 | myPanel.layout.layout(true); 46 | myPanel.grp.minimumSize = myPanel.grp.size; 47 | myPanel.layout.resize(); 48 | myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();} 49 | 50 | return myPanel; 51 | } 52 | 53 | // Build script panel 54 | var myScriptPal = myScript_buildUI(thisObj); 55 | 56 | if ((myScriptPal != null) && (myScriptPal instanceof Window)) { 57 | myScriptPal.center(); 58 | myScriptPal.show(); 59 | } 60 | } 61 | 62 | // Execute script 63 | myScript(this); 64 | } 65 | -------------------------------------------------------------------------------- /colorConversion.jsx: -------------------------------------------------------------------------------- 1 | // Converts hex string to 0-1 decimal format for AE. Returns string of AE Color 2 | function hexToAEColor(hexString){ 3 | var bigInt = parseInt(hexString.replace("#",""), 16); 4 | var r = (bigInt >> 16) & 255; 5 | var g = (bigInt >> 8) & 255; 6 | var b = bigInt & 255; 7 | return [r/255,g/255,b/255]; 8 | } 9 | 10 | 11 | 12 | // Converts AE color to hex string. Parameters: AE color array. Returns hex color (string) 13 | function aeColorToHex(aeColor){ 14 | var r = aeColor[0] * 255; var g = aeColor[1] * 255; var b = aeColor[2] * 255; 15 | function componentToHex(c) { 16 | var hex = c.toString(16); 17 | return hex.length == 1 ? "0" + hex : hex; 18 | } 19 | return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); 20 | } 21 | 22 | 23 | 24 | // Converts AE color array to normal RGB array 25 | function aeColorToRGB(aeColorArray){ 26 | var r = aeColorArray[0]; var g = aeColorArray[1]; var b = aeColorArray[2]; 27 | return [r*255,g*255,b*255]; 28 | } 29 | 30 | 31 | // Converts RGB array to AE color format. Returns array in AE color format 32 | function rgbToAEColor(rgbArray){ 33 | var r = rgbArray[0]; var g = rgbArray[1]; var b = rgbArray[2]; 34 | return [r/255,g/255,b/255]; 35 | } // End rgbToAEColor() function 36 | 37 | 38 | 39 | // Converts RGB array to HSL array 40 | function rgbToHSL(rgbArray){ 41 | var r = rgbArray[0] / 255; var g = rgbArray[1] / 255; var b = rgbArray[2] / 255; 42 | var max = Math.max(r, g, b), min = Math.min(r, g, b); 43 | var h, s, l = (max + min) / 2; 44 | 45 | if(max == min){ 46 | h = s = 0; // achromatic 47 | } else { 48 | var d = max - min; 49 | s = l > 0.5 ? d / (2 - max - min) : d / (max + min); 50 | switch(max){ 51 | case r: h = (g - b) / d + (g < b ? 6 : 0); break; 52 | case g: h = (b - r) / d + 2; break; 53 | case b: h = (r - g) / d + 4; break; 54 | } 55 | h /= 6; 56 | } 57 | return [h, s, l]; 58 | } // End of rgbToHSL() function 59 | 60 | 61 | 62 | // HSL to RGB. Returns RGB array 63 | function hslToRGB(hslArray){ 64 | var r,g,b,h,s,l; 65 | h = hslArray[0]; 66 | s = hslArray[1]; 67 | l = hslArray[2]; 68 | 69 | if(s == 0){ 70 | r = g = b = l; // achromatic 71 | }else{ 72 | var hue2rgb = function hue2rgb(p, q, t){ 73 | if(t < 0) t += 1; 74 | if(t > 1) t -= 1; 75 | if(t < 1/6) return p + (q - p) * 6 * t; 76 | if(t < 1/2) return q; 77 | if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; 78 | return p; 79 | } 80 | 81 | var q = l < 0.5 ? l * (1 + s) : l + s - l * s; 82 | var p = 2 * l - q; 83 | r = hue2rgb(p, q, h + 1/3); 84 | g = hue2rgb(p, q, h); 85 | b = hue2rgb(p, q, h - 1/3); 86 | } 87 | 88 | return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; 89 | } 90 | -------------------------------------------------------------------------------- /colorPicker.jsx: -------------------------------------------------------------------------------- 1 | // Initiates color picker, returns RGB array 2 | function colorPicker(){ 3 | var initialRGB = [1,1,1]; 4 | var colorInt = 255 * (65536 * initialRGB[0] + 256 * initialRGB[1] + initialRGB[2]); 5 | var c = $.colorPicker(colorInt); 6 | if (c == -1) return; 7 | var r = ((c >> 16) & 0xFF) ; 8 | var g = ((c >> 8) & 0xFF) ; 9 | var b = (c & 0xFF) ; 10 | return [r,g,b] 11 | } // End colorPicker() function 12 | -------------------------------------------------------------------------------- /convertToBinary.jsx: -------------------------------------------------------------------------------- 1 | function convertToBinary(fileObj) { 2 | fileObj.encoding = "BINARY"; 3 | fileObj.open('r'); 4 | var fileData = fileObj.read(); 5 | fileObj.close(); 6 | var binaryString = fileData.toSource(); 7 | 8 | binaryString = binaryString.replace(/^\(new String\(/, "["); 9 | binaryString = binaryString.replace(/\)\)$/, "];"); 10 | 11 | return "var myBin = " + binaryString; 12 | } 13 | --------------------------------------------------------------------------------