diff --git a/NO_TOC_README.md b/NO_TOC_README.md new file mode 100644 index 0000000..e463cbe --- /dev/null +++ b/NO_TOC_README.md @@ -0,0 +1,4 @@ +after-effects-script-snippets +============================= + +this is a loose collection of js snippets for After Effects \ No newline at end of file diff --git a/README.md b/README.md index e463cbe..10b4963 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,204 @@ after-effects-script-snippets ============================= -this is a loose collection of js snippets for After Effects \ No newline at end of file +this is a loose collection of js snippets for After Effects + +##Autogenerated TOC +###[__movetotop.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/__movetotop.jsx) +/** + * @author fabiantheblind + * @description moves all selected layers to the top of the comp + * + * + * @todo [description] + */ + +-------------- + +###[add-text.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/add-text.jsx) +/** + * @author fabiantheblind + * @description add textlayers from string. + * layers will be splitted by whitespaces + * + * @todo [description] + */ + +-------------- + +###[automagically-sort-layers-by-name.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/automagically-sort-layers-by-name.jsx) +/** + * This script tries to sort layers by name + * more a proof of concept thingy + * using this technique can hold some problems + * - in this case the "et" gets found in "consectetur" "et" "amet" + * - the last matching pattern will be the one that gets executed + */ + +-------------- + +###[automagically-sort-selectedlayers-by-name.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/automagically-sort-selectedlayers-by-name.jsx) +/** + * This script tries to sort layers by name + * more a proof of concept thingy + * using this technique can hold some problems + * - in this case the "et" gets found in "consectetur" "et" "amet" + * - the last matching pattern will be the one that gets executed + */ + +-------------- + +###[comp_with_text.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/comp_with_text.jsx) +/** + * @author fabiantheblind + * @description should create comps from a csv file + * + * + * @todo check if it works + */ + +-------------- + +###[connect-with-path.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/connect-with-path.jsx) +/** + * @author fabiantheblind + * @description tries to connect selected layers with a path + * + * + * @todo get also parented position and position with expressions + */ + +-------------- + +###[cycle-labels.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/cycle-labels.jsx) +/** + * @author fabiantheblind + * @description cycle thru label colors + * this is CS6+ feature I think + * + * @todo [description] + */ + +-------------- + +###[disable-expression.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/disable-expression.jsx) +/** + * @author fabiantheblind + * @description enable expression + * + * + * @todo [description] + */ + +-------------- + +###[distort-rotate-at-time.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/distort-rotate-at-time.jsx) +/** + * @author fabiantheblind + * @description Distord rotation keyframes at a certain time + * + * + * @todo [description] + */ + +-------------- + +###[duplicate_layer.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/duplicate_layer.jsx) +/** + * @author fabiantheblind + * @description duplicates a layer 99 times + * + * + * @todo [description] + */ + +-------------- + +###[project_selection_to_grid.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/project_selection_to_grid.jsx) +/** + * @author fabiantheblind + * @description creates from the selected layer in the project panel a grind in te current comp + * + * + * @todo [description] + */ + +-------------- + +###[randomOrderSelectedLayers.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/randomOrderSelectedLayers.jsx) +/** + * @author Dan Ebberts + * @description randomize order of layers + * random order found on: http://forums.creativecow.net/thread/227/10609 + * by Dan Ebberts + * @todo [description] + */ + +-------------- + +###[rename-layers-with-padded-number.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/rename-layers-with-padded-number.jsx) +/** + * @author fabiantheblind + * @description pad all layernames + * + * + * @todo [description] + */ + +-------------- + +###[rename-layers.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/rename-layers.jsx) +/** + * @author fabiantheblind + * @description rename selected layers with number + * this happens in comp and project panel + * + * + * @todo catch error if layer as no source + +-------------- + +###[select-all-masks-on laayer.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/select-all-masks-on laayer.jsx) +/** + * @author redefinery with some edits by fabiantheblind + * @description select all masks on layer + * take a look into the fundamentals + * http://www.redefinery.com/ae/fundamentals/ + * @todo [description] + */ + +-------------- + +###[set-get-settings.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/set-get-settings.jsx) +/** + * @author fabiantheblind + * @description this is a AE Settings Class + * + * + * @todo implement features like Array and Object saving + */ + +-------------- + +###[sort_text_layers_by_content.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/sort_text_layers_by_content.jsx) +/** + * @author fabiantheblind + * @description this sorts layers by their content + * + * + * @todo [description] + */ + +-------------- + +###[text_to_comp.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/text_to_comp.jsx) +/** + * @author fabiantheblind + * @description adds text to a comp with UI + * + * + * @todo check if it works + */ + +-------------- + diff --git a/TOC.md b/TOC.md new file mode 100644 index 0000000..5dc19d1 --- /dev/null +++ b/TOC.md @@ -0,0 +1,199 @@ +##Autogenerated TOC +###[__movetotop.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/__movetotop.jsx) +/** + * @author fabiantheblind + * @description moves all selected layers to the top of the comp + * + * + * @todo [description] + */ + +-------------- + +###[add-text.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/add-text.jsx) +/** + * @author fabiantheblind + * @description add textlayers from string. + * layers will be splitted by whitespaces + * + * @todo [description] + */ + +-------------- + +###[automagically-sort-layers-by-name.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/automagically-sort-layers-by-name.jsx) +/** + * This script tries to sort layers by name + * more a proof of concept thingy + * using this technique can hold some problems + * - in this case the "et" gets found in "consectetur" "et" "amet" + * - the last matching pattern will be the one that gets executed + */ + +-------------- + +###[automagically-sort-selectedlayers-by-name.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/automagically-sort-selectedlayers-by-name.jsx) +/** + * This script tries to sort layers by name + * more a proof of concept thingy + * using this technique can hold some problems + * - in this case the "et" gets found in "consectetur" "et" "amet" + * - the last matching pattern will be the one that gets executed + */ + +-------------- + +###[comp_with_text.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/comp_with_text.jsx) +/** + * @author fabiantheblind + * @description should create comps from a csv file + * + * + * @todo check if it works + */ + +-------------- + +###[connect-with-path.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/connect-with-path.jsx) +/** + * @author fabiantheblind + * @description tries to connect selected layers with a path + * + * + * @todo get also parented position and position with expressions + */ + +-------------- + +###[cycle-labels.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/cycle-labels.jsx) +/** + * @author fabiantheblind + * @description cycle thru label colors + * this is CS6+ feature I think + * + * @todo [description] + */ + +-------------- + +###[disable-expression.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/disable-expression.jsx) +/** + * @author fabiantheblind + * @description enable expression + * + * + * @todo [description] + */ + +-------------- + +###[distort-rotate-at-time.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/distort-rotate-at-time.jsx) +/** + * @author fabiantheblind + * @description Distord rotation keyframes at a certain time + * + * + * @todo [description] + */ + +-------------- + +###[duplicate_layer.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/duplicate_layer.jsx) +/** + * @author fabiantheblind + * @description duplicates a layer 99 times + * + * + * @todo [description] + */ + +-------------- + +###[project_selection_to_grid.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/project_selection_to_grid.jsx) +/** + * @author fabiantheblind + * @description creates from the selected layer in the project panel a grind in te current comp + * + * + * @todo [description] + */ + +-------------- + +###[randomOrderSelectedLayers.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/randomOrderSelectedLayers.jsx) +/** + * @author Dan Ebberts + * @description randomize order of layers + * random order found on: http://forums.creativecow.net/thread/227/10609 + * by Dan Ebberts + * @todo [description] + */ + +-------------- + +###[rename-layers-with-padded-number.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/rename-layers-with-padded-number.jsx) +/** + * @author fabiantheblind + * @description pad all layernames + * + * + * @todo [description] + */ + +-------------- + +###[rename-layers.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/rename-layers.jsx) +/** + * @author fabiantheblind + * @description rename selected layers with number + * this happens in comp and project panel + * + * + * @todo catch error if layer as no source + +-------------- + +###[select-all-masks-on laayer.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/select-all-masks-on laayer.jsx) +/** + * @author redefinery with some edits by fabiantheblind + * @description select all masks on layer + * take a look into the fundamentals + * http://www.redefinery.com/ae/fundamentals/ + * @todo [description] + */ + +-------------- + +###[set-get-settings.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/set-get-settings.jsx) +/** + * @author fabiantheblind + * @description this is a AE Settings Class + * + * + * @todo implement features like Array and Object saving + */ + +-------------- + +###[sort_text_layers_by_content.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/sort_text_layers_by_content.jsx) +/** + * @author fabiantheblind + * @description this sorts layers by their content + * + * + * @todo [description] + */ + +-------------- + +###[text_to_comp.jsx](https://raw.github.com/fabiantheblind/after-effects-script-snippets/master/text_to_comp.jsx) +/** + * @author fabiantheblind + * @description adds text to a comp with UI + * + * + * @todo check if it works + */ + +-------------- + diff --git a/__movetotop.jsx b/__movetotop.jsx index 22d451b..3d13722 100644 --- a/__movetotop.jsx +++ b/__movetotop.jsx @@ -1,3 +1,10 @@ +/** + * @author fabiantheblind + * @description moves all selected layers to the top of the comp + * + * + * @todo [description] + */ (function(thisObj){ // basic panel mpo_import(thisObj); @@ -11,12 +18,12 @@ import_data = { }; -/// THIS WILL CHECK IF PANEL IS DOCKABLE OR FLAOTING WINDOW +/// THIS WILL CHECK IF PANEL IS DOCKABLE OR FLAOTING WINDOW var win = buildUI(thisObj ); if ((win !== null) && (win instanceof Window)) { win.center(); win.show(); -} // end if win null and not a instance of window +} // end if win null and not a instance of window function buildUI (thisObj ) { var win = (thisObj instanceof Panel) ? thisObj : new Window('palette', 'FSS Fake Parallax',[0,0,150,260],{resizeable: true}); @@ -32,7 +39,7 @@ if ((win !== null) && (win instanceof Window)) { // win.check_box = win.add('checkbox',[x,y,x+W*2,y + H],'check'); // win.check_box.value = metaObject.setting1; win.do_it_button = win.add('button', [x ,y,x+W*3,y + H], 'do it'); - // win.up_button = win.add('button', [x + W*5+ G,y,x + W*6,y + H], 'Up'); + // win.up_button = win.add('button', [x + W*5+ G,y,x + W*6,y + H], 'Up'); // win.check_box.onClick = function (){ // alert("check"); @@ -48,7 +55,7 @@ if ((win !== null) && (win instanceof Window)) { function runit(){ // "in function main. From here on it is a straight run" -// +// var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ diff --git a/add-text.jsx b/add-text.jsx index bd27ba3..aec1d76 100644 --- a/add-text.jsx +++ b/add-text.jsx @@ -1 +1,28 @@ -fun(); function fun(){ str = prompt("Enter Your Text Here",""); if(str.length < 1 ) return; app.beginUndoGroup("XXX"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; var arr = str.split(" "); for(var i = 0; i < arr.length;i++){ curComp.layers.addText(arr[i]); } app.endUndoGroup(); } \ No newline at end of file +/** + * @author fabiantheblind + * @description add textlayers from string. + * layers will be splitted by whitespaces + * + * @todo [description] + */ +fun(); +function fun(){ + +str = prompt("Enter Your Text Here",""); +if(str.length < 1 ) return; +app.beginUndoGroup("XXX"); + +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + +var arr = str.split(" "); +for(var i = 0; i < arr.length;i++){ +curComp.layers.addText(arr[i]); + } + + +app.endUndoGroup(); +} \ No newline at end of file diff --git a/automagically-sort-layers-by-name.jsx b/automagically-sort-layers-by-name.jsx index 5c15d5f..5b7a330 100644 --- a/automagically-sort-layers-by-name.jsx +++ b/automagically-sort-layers-by-name.jsx @@ -1 +1,177 @@ -/** * This script tries to sort layers by name * more a proof of concept thingy * using this technique can hold some problems * - in this case the "et" gets found in "consectetur" "et" "amet" * - the last matching pattern will be the one that gets executed * */ // Copyright (c) 2013 // Fabian "fabiantheblind" Morón Zirfas // Permission is hereby granted, free of charge, to any // person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to // whom the Software is furnished to do so, subject to // the following conditions: // The above copyright notice and this permission notice // shall be included in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // see also http://www.opensource.org/licenses/mit-license.php /** * get unique Array content * does not work on mixed arrays * http://stackoverflow.com/questions/1960473/unique-values-in-an-array * @return {Array} [description] */ Array.prototype.getUnique = function(){ var u = {}, a = []; for(var i = 0, l = this.length; i < l; ++i){ if(u.hasOwnProperty(this[i])) { continue; } a.push(this[i]); u[this[i]] = 1; } return a; }; /** * LayerSet Class * @param {String} _name The name of the class corresponds to the pattern */ function LayerSet(_name){ this.name = _name; this.collection = [];// will hold layers this.add = function(layer){ this.collection.push(layer); }; } /** * A Pattern Class * @param {a regex string} _reg String */ function Pattern(_reg){ this.reg = escapeRegExp(_reg); } function automagically_sort(){ app.beginUndoGroup("automagically sort by name"); /** * prerequisites check if thete is a comp * @type {[type]} */ var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ // alert("noComp"); // return; curComp = app.project.items.addComp("automagically sort", 500, 500, 1, 10, 25); } var names = ["Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua","Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua"];// some random names var layers = [];// holds the layers for(var l = 0; l < names.length;l++){ var lay = curComp.layers.addNull();// add a null lay.name = makeid(4) + " " + names[l] + " " + makeid(5); // give it a name layers.push(lay);// push to array } // close l create layers loop. // this shoudl be a space seprated field or something like that var unique_names = names.getUnique(); // use the prototype functiion var patterns = []; // this will hold the patterns for (var n = 0; n < unique_names.length; n++) { patterns.push( new Pattern( unique_names[n])); } // close ncreate patterns from names loop var sets = []; // will hold all the layer sets for(var r =0;r < patterns.length;r++){ var set = new LayerSet(patterns[r].reg);// make a new set per pattern for (var i = 0; i < layers.length; i++) { var layer = layers[i];//isolate var reg = new RegExp( patterns[r].reg ,'g');// make a regex if(reg.test(layer.name) === true){ set.add(layer);// Yes found something push to LayerSet } // close regex check } // close i layers loop if(set.collection.length > 0){ sets.push(set); } }// close r pattern loop /** * Now the sorting * We need to get every item from the set and move it to the top */ // alert(sets.toSource()); for (var s = 0; s < sets.length; s++) { var curSet = sets[s];// isolate if(curSet.collection.length > 0){ // continue; // we have something in the set loop the collection var collabel = (s)%16; for (var cl = 0; cl < curSet.collection.length; cl++) { var curLayer = curSet.collection[cl]; curLayer.moveToBeginning(); if(parseInt (app.version, 10) > 10){ // CS6+ feature curLayer.label = collabel; } } // end cl collection loop }// if there are no layers move to the next set } // end s sets loop app.endUndoGroup(); } /** * [escapeRegExp description] * @param {[type]} str [description] * @return {[type]} [description] * http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex */ function escapeRegExp(str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); } /** * Make pseudo random text found here * http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript * @return {String} [Pseudo random string] */ function makeid(num){ var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < num; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } // _ _ ______ _______ _ _ _ _ _____ _______ _______ _____ _ _ _____ // | \ | |/ __ \ \ / / __ \| | | | \ | | __ \ /\|__ __|__ __|_ _| \ | |/ ____| // | \| | | | \ \ /\ / /| |__) | | | | \| | | | | / \ | | | | | | | \| | | __ // | . ` | | | |\ \/ \/ / | _ /| | | | . ` | | | |/ /\ \ | | | | | | | . ` | | |_ | // | |\ | |__| | \ /\ / | | \ \| |__| | |\ | |__| / ____ \| | | | _| |_| |\ | |__| | // |_| \_|\____/ \/ \/ |_| \_\\____/|_| \_|_____/_/ \_\_| |_| |_____|_| \_|\_____| automagically_sort(); \ No newline at end of file +/** + * This script tries to sort layers by name + * more a proof of concept thingy + * using this technique can hold some problems + * - in this case the "et" gets found in "consectetur" "et" "amet" + * - the last matching pattern will be the one that gets executed + */ + +// Copyright (c) 2013 +// Fabian "fabiantheblind" Morón Zirfas +// Permission is hereby granted, free of charge, to any +// person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to +// whom the Software is furnished to do so, subject to +// the following conditions: +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// see also http://www.opensource.org/licenses/mit-license.php + +/** + * get unique Array content + * does not work on mixed arrays + * http://stackoverflow.com/questions/1960473/unique-values-in-an-array + * @return {Array} [description] + */ +Array.prototype.getUnique = function(){ + var u = {}, a = []; + for(var i = 0, l = this.length; i < l; ++i){ + if(u.hasOwnProperty(this[i])) { + continue; + } + a.push(this[i]); + u[this[i]] = 1; + } + return a; +}; + +/** + * LayerSet Class + * @param {String} _name The name of the class corresponds to the pattern + */ +function LayerSet(_name){ + this.name = _name; + this.collection = [];// will hold layers + + this.add = function(layer){ + this.collection.push(layer); + }; +} +/** + * A Pattern Class + * @param {a regex string} _reg String + */ +function Pattern(_reg){ + this.reg = escapeRegExp(_reg); +} + + +function automagically_sort(){ + + +app.beginUndoGroup("automagically sort by name"); +/** + * prerequisites check if thete is a comp + * @type {[type]} + */ +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + // alert("noComp"); + // return; + curComp = app.project.items.addComp("automagically sort", 500, 500, 1, 10, 25); + } + +var names = ["Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua","Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua"];// some random names +var layers = [];// holds the layers +for(var l = 0; l < names.length;l++){ + var lay = curComp.layers.addNull();// add a null + lay.name = makeid(4) + " " + names[l] + " " + makeid(5); // give it a name + layers.push(lay);// push to array +} // close l create layers loop. // this shoudl be a space seprated field or something like that + + +var unique_names = names.getUnique(); // use the prototype functiion +var patterns = []; // this will hold the patterns +for (var n = 0; n < unique_names.length; n++) { + patterns.push( new Pattern( unique_names[n])); +} // close ncreate patterns from names loop + +var sets = []; // will hold all the layer sets +for(var r =0;r < patterns.length;r++){ + var set = new LayerSet(patterns[r].reg);// make a new set per pattern + for (var i = 0; i < layers.length; i++) { + var layer = layers[i];//isolate + var reg = new RegExp( patterns[r].reg ,'g');// make a regex + if(reg.test(layer.name) === true){ + set.add(layer);// Yes found something push to LayerSet + } // close regex check + } // close i layers loop + if(set.collection.length > 0){ + sets.push(set); + } +}// close r pattern loop + + + +/** + * Now the sorting + * We need to get every item from the set and move it to the top + */ + +// alert(sets.toSource()); +for (var s = 0; s < sets.length; s++) { + var curSet = sets[s];// isolate + if(curSet.collection.length > 0){ + // continue; + // we have something in the set loop the collection + var collabel = (s)%16; + for (var cl = 0; cl < curSet.collection.length; cl++) { + var curLayer = curSet.collection[cl]; + curLayer.moveToBeginning(); + if(parseInt (app.version, 10) > 10){ + // CS6+ feature + curLayer.label = collabel; + } + } // end cl collection loop + }// if there are no layers move to the next set +} // end s sets loop +app.endUndoGroup(); +} + + +/** + * [escapeRegExp description] + * @param {[type]} str [description] + * @return {[type]} [description] + * http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex + */ +function escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +} + + +/** + * Make pseudo random text found here + * http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript + * @return {String} [Pseudo random string] + */ +function makeid(num){ + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for( var i=0; i < num; i++ ) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} + + + // _ _ ______ _______ _ _ _ _ _____ _______ _______ _____ _ _ _____ + // | \ | |/ __ \ \ / / __ \| | | | \ | | __ \ /\|__ __|__ __|_ _| \ | |/ ____| + // | \| | | | \ \ /\ / /| |__) | | | | \| | | | | / \ | | | | | | | \| | | __ + // | . ` | | | |\ \/ \/ / | _ /| | | | . ` | | | |/ /\ \ | | | | | | | . ` | | |_ | + // | |\ | |__| | \ /\ / | | \ \| |__| | |\ | |__| / ____ \| | | | _| |_| |\ | |__| | + // |_| \_|\____/ \/ \/ |_| \_\\____/|_| \_|_____/_/ \_\_| |_| |_____|_| \_|\_____| + +automagically_sort(); \ No newline at end of file diff --git a/automagically-sort-selectedlayers-by-name.jsx b/automagically-sort-selectedlayers-by-name.jsx index 5c15d5f..5b7a330 100644 --- a/automagically-sort-selectedlayers-by-name.jsx +++ b/automagically-sort-selectedlayers-by-name.jsx @@ -1 +1,177 @@ -/** * This script tries to sort layers by name * more a proof of concept thingy * using this technique can hold some problems * - in this case the "et" gets found in "consectetur" "et" "amet" * - the last matching pattern will be the one that gets executed * */ // Copyright (c) 2013 // Fabian "fabiantheblind" Morón Zirfas // Permission is hereby granted, free of charge, to any // person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to // whom the Software is furnished to do so, subject to // the following conditions: // The above copyright notice and this permission notice // shall be included in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // see also http://www.opensource.org/licenses/mit-license.php /** * get unique Array content * does not work on mixed arrays * http://stackoverflow.com/questions/1960473/unique-values-in-an-array * @return {Array} [description] */ Array.prototype.getUnique = function(){ var u = {}, a = []; for(var i = 0, l = this.length; i < l; ++i){ if(u.hasOwnProperty(this[i])) { continue; } a.push(this[i]); u[this[i]] = 1; } return a; }; /** * LayerSet Class * @param {String} _name The name of the class corresponds to the pattern */ function LayerSet(_name){ this.name = _name; this.collection = [];// will hold layers this.add = function(layer){ this.collection.push(layer); }; } /** * A Pattern Class * @param {a regex string} _reg String */ function Pattern(_reg){ this.reg = escapeRegExp(_reg); } function automagically_sort(){ app.beginUndoGroup("automagically sort by name"); /** * prerequisites check if thete is a comp * @type {[type]} */ var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ // alert("noComp"); // return; curComp = app.project.items.addComp("automagically sort", 500, 500, 1, 10, 25); } var names = ["Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua","Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua"];// some random names var layers = [];// holds the layers for(var l = 0; l < names.length;l++){ var lay = curComp.layers.addNull();// add a null lay.name = makeid(4) + " " + names[l] + " " + makeid(5); // give it a name layers.push(lay);// push to array } // close l create layers loop. // this shoudl be a space seprated field or something like that var unique_names = names.getUnique(); // use the prototype functiion var patterns = []; // this will hold the patterns for (var n = 0; n < unique_names.length; n++) { patterns.push( new Pattern( unique_names[n])); } // close ncreate patterns from names loop var sets = []; // will hold all the layer sets for(var r =0;r < patterns.length;r++){ var set = new LayerSet(patterns[r].reg);// make a new set per pattern for (var i = 0; i < layers.length; i++) { var layer = layers[i];//isolate var reg = new RegExp( patterns[r].reg ,'g');// make a regex if(reg.test(layer.name) === true){ set.add(layer);// Yes found something push to LayerSet } // close regex check } // close i layers loop if(set.collection.length > 0){ sets.push(set); } }// close r pattern loop /** * Now the sorting * We need to get every item from the set and move it to the top */ // alert(sets.toSource()); for (var s = 0; s < sets.length; s++) { var curSet = sets[s];// isolate if(curSet.collection.length > 0){ // continue; // we have something in the set loop the collection var collabel = (s)%16; for (var cl = 0; cl < curSet.collection.length; cl++) { var curLayer = curSet.collection[cl]; curLayer.moveToBeginning(); if(parseInt (app.version, 10) > 10){ // CS6+ feature curLayer.label = collabel; } } // end cl collection loop }// if there are no layers move to the next set } // end s sets loop app.endUndoGroup(); } /** * [escapeRegExp description] * @param {[type]} str [description] * @return {[type]} [description] * http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex */ function escapeRegExp(str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); } /** * Make pseudo random text found here * http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript * @return {String} [Pseudo random string] */ function makeid(num){ var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < num; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } // _ _ ______ _______ _ _ _ _ _____ _______ _______ _____ _ _ _____ // | \ | |/ __ \ \ / / __ \| | | | \ | | __ \ /\|__ __|__ __|_ _| \ | |/ ____| // | \| | | | \ \ /\ / /| |__) | | | | \| | | | | / \ | | | | | | | \| | | __ // | . ` | | | |\ \/ \/ / | _ /| | | | . ` | | | |/ /\ \ | | | | | | | . ` | | |_ | // | |\ | |__| | \ /\ / | | \ \| |__| | |\ | |__| / ____ \| | | | _| |_| |\ | |__| | // |_| \_|\____/ \/ \/ |_| \_\\____/|_| \_|_____/_/ \_\_| |_| |_____|_| \_|\_____| automagically_sort(); \ No newline at end of file +/** + * This script tries to sort layers by name + * more a proof of concept thingy + * using this technique can hold some problems + * - in this case the "et" gets found in "consectetur" "et" "amet" + * - the last matching pattern will be the one that gets executed + */ + +// Copyright (c) 2013 +// Fabian "fabiantheblind" Morón Zirfas +// Permission is hereby granted, free of charge, to any +// person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to +// whom the Software is furnished to do so, subject to +// the following conditions: +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// see also http://www.opensource.org/licenses/mit-license.php + +/** + * get unique Array content + * does not work on mixed arrays + * http://stackoverflow.com/questions/1960473/unique-values-in-an-array + * @return {Array} [description] + */ +Array.prototype.getUnique = function(){ + var u = {}, a = []; + for(var i = 0, l = this.length; i < l; ++i){ + if(u.hasOwnProperty(this[i])) { + continue; + } + a.push(this[i]); + u[this[i]] = 1; + } + return a; +}; + +/** + * LayerSet Class + * @param {String} _name The name of the class corresponds to the pattern + */ +function LayerSet(_name){ + this.name = _name; + this.collection = [];// will hold layers + + this.add = function(layer){ + this.collection.push(layer); + }; +} +/** + * A Pattern Class + * @param {a regex string} _reg String + */ +function Pattern(_reg){ + this.reg = escapeRegExp(_reg); +} + + +function automagically_sort(){ + + +app.beginUndoGroup("automagically sort by name"); +/** + * prerequisites check if thete is a comp + * @type {[type]} + */ +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + // alert("noComp"); + // return; + curComp = app.project.items.addComp("automagically sort", 500, 500, 1, 10, 25); + } + +var names = ["Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua","Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua"];// some random names +var layers = [];// holds the layers +for(var l = 0; l < names.length;l++){ + var lay = curComp.layers.addNull();// add a null + lay.name = makeid(4) + " " + names[l] + " " + makeid(5); // give it a name + layers.push(lay);// push to array +} // close l create layers loop. // this shoudl be a space seprated field or something like that + + +var unique_names = names.getUnique(); // use the prototype functiion +var patterns = []; // this will hold the patterns +for (var n = 0; n < unique_names.length; n++) { + patterns.push( new Pattern( unique_names[n])); +} // close ncreate patterns from names loop + +var sets = []; // will hold all the layer sets +for(var r =0;r < patterns.length;r++){ + var set = new LayerSet(patterns[r].reg);// make a new set per pattern + for (var i = 0; i < layers.length; i++) { + var layer = layers[i];//isolate + var reg = new RegExp( patterns[r].reg ,'g');// make a regex + if(reg.test(layer.name) === true){ + set.add(layer);// Yes found something push to LayerSet + } // close regex check + } // close i layers loop + if(set.collection.length > 0){ + sets.push(set); + } +}// close r pattern loop + + + +/** + * Now the sorting + * We need to get every item from the set and move it to the top + */ + +// alert(sets.toSource()); +for (var s = 0; s < sets.length; s++) { + var curSet = sets[s];// isolate + if(curSet.collection.length > 0){ + // continue; + // we have something in the set loop the collection + var collabel = (s)%16; + for (var cl = 0; cl < curSet.collection.length; cl++) { + var curLayer = curSet.collection[cl]; + curLayer.moveToBeginning(); + if(parseInt (app.version, 10) > 10){ + // CS6+ feature + curLayer.label = collabel; + } + } // end cl collection loop + }// if there are no layers move to the next set +} // end s sets loop +app.endUndoGroup(); +} + + +/** + * [escapeRegExp description] + * @param {[type]} str [description] + * @return {[type]} [description] + * http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex + */ +function escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +} + + +/** + * Make pseudo random text found here + * http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript + * @return {String} [Pseudo random string] + */ +function makeid(num){ + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for( var i=0; i < num; i++ ) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} + + + // _ _ ______ _______ _ _ _ _ _____ _______ _______ _____ _ _ _____ + // | \ | |/ __ \ \ / / __ \| | | | \ | | __ \ /\|__ __|__ __|_ _| \ | |/ ____| + // | \| | | | \ \ /\ / /| |__) | | | | \| | | | | / \ | | | | | | | \| | | __ + // | . ` | | | |\ \/ \/ / | _ /| | | | . ` | | | |/ /\ \ | | | | | | | . ` | | |_ | + // | |\ | |__| | \ /\ / | | \ \| |__| | |\ | |__| / ____ \| | | | _| |_| |\ | |__| | + // |_| \_|\____/ \/ \/ |_| \_\\____/|_| \_|_____/_/ \_\_| |_| |_____|_| \_|\_____| + +automagically_sort(); \ No newline at end of file diff --git a/comp_with_text.jsx b/comp_with_text.jsx index 064ea7a..773002d 100644 --- a/comp_with_text.jsx +++ b/comp_with_text.jsx @@ -1 +1,191 @@ -comp_from_text(); function comp_from_text(){ var meta = { "w":1280, "h":720, "aspect":1, "dur":20, "rate":25, "data" :null }; meta.data = get_data(); if(meta.data === null){ alert("Data is null"); return; } app.beginUndoGroup("comp from text"); var proj = app.project; var curComp = proj.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; } for(var r = 0; r < meta.data.fields.length; r++){ var nc = proj.items.addComp( "scene " + String(r+1), meta.w, meta.h, meta.aspect, meta.dur, meta.rate); // for(var f = 0; f < meta.data.fields.length;f++){ // var tl = nc.addText(meta.data.fields[f].value); // } curComp.layers.add(nc, meta.dur); } app.endUndoGroup(); } function get_data () { // alert(this.text); var textLines = read_in_txt(); var rawdata = null; if(textLines !== null){ // markers = lines_to_markers(textLines); var res = textlines_to_data(textLines,","); // alert(res.toSource()); rawdata = res; // reading the textlines worked if it wasnt null if(rawdata !== null){ // alert(rawdata.fields[0].field + " "+rawdata.fields[0].value); return rawdata; }else{ return null; }// end of else textLines !== null } } /** * gets lines of strings and creates the data we need from * CSV Header and content * @param {Array of String} textLines are , or \t separeted values * @return {Object} */ function textlines_to_data(textLines,separator){ var data = {}; data.fields = []; data.keys = []; for(var i = 0; i < textLines.length;i++){ var line = []; var line_arr = split_csv(separator,textLines[i]); if(i === 0){ for(var j = 0; j < line_arr.length;j++){ data.keys[j] = line_arr[j]; } }else{ var obj = {}; for(var k = 0; k < line_arr.length;k++){ // if(k !== line_arr.length -1){ // obj_str += 'field_' + k + ':"' + line_arr[k] + '",'; // }else{ // obj_str += 'field_' + k + ':"' + line_arr[k] + '"'; // } line.push({'field':k,"value":line_arr[k]}); } // end k loop } // end else data.fields.push(line); } // end i loop return data; } function split_textline(line){ // var arr = line.split("\t"); var arr = line.split(/[,\t]/); return arr; } /** * This is a string prototype function * found here http://www.greywyvern.com/?post=258 * @param {String} sep is the separator we use only , * @return {Array} returns an Array of strings */ // String.prototype.splitCSV = function(sep) { // for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) { // if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') { // if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') { // foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"'); // } else if (x) { // foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep)); // } else foo = foo.shift().split(sep).concat(foo); // } else foo[x].replace(/""/g, '"'); // } return foo; // }; // Dont use prototypes? // for the time beeing YES // Makes problems with other scripts // or we need to use a unique prefix! like ftb_splitCSV function split_csv (sep,the_string){ for (var foo = the_string.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) { if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') { if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') { foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"'); } else if (x) { foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep)); } else foo = foo.shift().split(sep).concat(foo); } else foo[x].replace(/""/g, '"'); } return foo; } /** * this reads in a file * line by line * @return {Array of String} */ function read_in_txt(){ var textFile = File.openDialog("Select a text file to import.", "*.*",false); var textLines = []; if (textFile !== null) { textFile.open('r', undefined, undefined); while (!textFile.eof){ textLines[textLines.length] = textFile.readln(); } textFile.close(); } if(!textLines){ alert("ERROR Reading file"); return null; }else{ return textLines; } } \ No newline at end of file +/** + * @author fabiantheblind + * @description should create comps from a csv file + * + * + * @todo check if it works + */ +comp_from_text(); +function comp_from_text(){ + +var meta = { + "w":1280, + "h":720, + "aspect":1, + "dur":20, + "rate":25, + "data" :null +}; + +meta.data = get_data(); + +if(meta.data === null){ + alert("Data is null"); + return; +} + +app.beginUndoGroup("comp from text"); +var proj = app.project; +var curComp = proj.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + + +for(var r = 0; r < meta.data.fields.length; r++){ + +var nc = proj.items.addComp( + "scene " + String(r+1), + meta.w, + meta.h, + meta.aspect, + meta.dur, + meta.rate); + // for(var f = 0; f < meta.data.fields.length;f++){ + // var tl = nc.addText(meta.data.fields[f].value); + // } + curComp.layers.add(nc, meta.dur); +} + + +app.endUndoGroup(); +} + + +function get_data () { + // alert(this.text); + var textLines = read_in_txt(); + var rawdata = null; + if(textLines !== null){ + // markers = lines_to_markers(textLines); + var res = textlines_to_data(textLines,","); + // alert(res.toSource()); + rawdata = res; + // reading the textlines worked if it wasnt null + if(rawdata !== null){ + +// alert(rawdata.fields[0].field + " "+rawdata.fields[0].value); +return rawdata; + + +}else{ + +return null; +}// end of else textLines !== null +} + +} +/** + * gets lines of strings and creates the data we need from + * CSV Header and content + * @param {Array of String} textLines are , or \t separeted values + * @return {Object} + */ +function textlines_to_data(textLines,separator){ + + var data = {}; + data.fields = []; + data.keys = []; + + for(var i = 0; i < textLines.length;i++){ + var line = []; + var line_arr = split_csv(separator,textLines[i]); + if(i === 0){ + for(var j = 0; j < line_arr.length;j++){ + data.keys[j] = line_arr[j]; + } + + }else{ + var obj = {}; + for(var k = 0; k < line_arr.length;k++){ + + // if(k !== line_arr.length -1){ + // obj_str += 'field_' + k + ':"' + line_arr[k] + '",'; + // }else{ + // obj_str += 'field_' + k + ':"' + line_arr[k] + '"'; + // } + line.push({'field':k,"value":line_arr[k]}); + } // end k loop + } // end else + data.fields.push(line); + } // end i loop + + return data; +} + +function split_textline(line){ + // var arr = line.split("\t"); + var arr = line.split(/[,\t]/); + +return arr; +} + +/** + * This is a string prototype function + * found here http://www.greywyvern.com/?post=258 + * @param {String} sep is the separator we use only , + * @return {Array} returns an Array of strings + */ +// String.prototype.splitCSV = function(sep) { +// for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) { +// if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') { +// if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') { +// foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"'); +// } else if (x) { +// foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep)); +// } else foo = foo.shift().split(sep).concat(foo); +// } else foo[x].replace(/""/g, '"'); +// } return foo; +// }; + + +// Dont use prototypes? +// for the time beeing YES +// Makes problems with other scripts +// or we need to use a unique prefix! like ftb_splitCSV + +function split_csv (sep,the_string){ + +for (var foo = the_string.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) { + if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') { + if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') { + foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"'); + } else if (x) { + foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep)); + } else foo = foo.shift().split(sep).concat(foo); + } else foo[x].replace(/""/g, '"'); + } + return foo; +} + + +/** + * this reads in a file + * line by line + * @return {Array of String} + */ +function read_in_txt(){ + + var textFile = File.openDialog("Select a text file to import.", "*.*",false); + + + + var textLines = []; + if (textFile !== null) { + textFile.open('r', undefined, undefined); + while (!textFile.eof){ + textLines[textLines.length] = textFile.readln(); + } + + textFile.close(); + } + + if(!textLines){ + alert("ERROR Reading file"); + return null; + }else{ + + return textLines; + } +} \ No newline at end of file diff --git a/connect-with-path.jsx b/connect-with-path.jsx index fac6b80..89ab70a 100644 --- a/connect-with-path.jsx +++ b/connect-with-path.jsx @@ -1 +1,256 @@ -(function(thisObj){ // basic panel mpo_import(thisObj); function mpo_import(thisObj){ // this is global import_data = { 'x':10, 'y':10 }; /// THIS WILL CHECK IF PANEL IS DOCKABLE OR FLAOTING WINDOW var win = buildUI(thisObj ); if ((win !== null) && (win instanceof Window)) { win.center(); win.show(); } // end if win null and not a instance of window function buildUI (thisObj ) { var H = 25; // the height var W = 30; // the width var G = 5; // the gutter var x = G; var y = G; var rownum = 1; var columnnum = 3; var gutternum = 2; var win = (thisObj instanceof Panel) ? thisObj : new Window('palette', 'Connect With Path',[0,0,gutternum*G + W*columnnum,gutternum*G + H*rownum],{resizeable: true}); if (win !== null) { // win.check_box = win.add('checkbox',[x,y,x+W*2,y + H],'check'); // win.check_box.value = metaObject.setting1; win.do_it_button = win.add('button', [x ,y,x+W*3,y + H], 'connect them'); // win.up_button = win.add('button', [x + W*5+ G,y,x + W*6,y + H], 'Up'); // win.check_box.onClick = function (){ // alert("check"); // }; win.do_it_button.onClick = function () { connect_all_layers(); }; } return win; } function connect_all_layers(){ // "in function main. From here on it is a straight run" // var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert('please select a comp'); return; } if(curComp.selectedLayers.length < 2){ alert('Please select at least an even number of layer'); return; } app.beginUndoGroup('connect-layers'); var buffer = curComp.layers.addNull(); buffer.name = "buffer"; var layerlist = []; for(var i = 0; i < curComp.selectedLayers.length;i+=2){ var lays = [ curComp.selectedLayers[i] , curComp.selectedLayers[i+1]]; layerlist.push(lays); } var shapes = []; for(var j = 0; j < layerlist.length; j++){ var global_curr_pos = [0, 0, 0]; var p1 = get_position(layerlist[j][0], curComp.time, buffer);;//layerlist[j][0].transform.position.value; // var p2 = get_position(layerlist[j][1], curComp.time, buffer); //layerlist[j][1].transform.position.value; var n = layerlist[j][0].name + " <-> " +layerlist[j][1].name; shapes.push(connect(p1 ,p2 , curComp, n)); } for(var k = 0; k < shapes.length;k++){ shapes[k].selected = true; } app.endUndoGroup(); } function connect(pos1, pos2, comp, name){ var curshape = comp.layers.addShape(); curshape.name = name; make_path([ [ pos1[0]- comp.width / 2,pos1[1]- comp.width / 2 ],[ pos2[0] - comp.width / 2,pos2[1] - comp.width / 2 ] ],curshape,true,null); return curshape; } /** * Path creation. As always the basis is taken from * http://www.redefinery.com/ae/fundamentals/ * * http://www.redefinery.com/ae/fundamentals/masks/ * with some additions to fit my needs * Still... Thanks 2 Jeff Almasol aka redefinery * * * * this builds a path using ternary operators * I like it that why a lot. Pretty slick * http://stackoverflow.com/questions/1771786/question-mark-in-javascript * * @param {Array of Arrays} path holds the coordinates for the path * @param {AVLayer} layer The layer to draw on * @param {String} rowname This is to sort ot rows * @param {String} pathname The name of the path * @param {Array of 3 Values 0 -1 } maskcolor The color of the masks always per Glyph * @param {ADBE Vectors Group} shapegroup The group that contains the path * @return {ADBE Vectors Group} for reuse. * * @todo Get the hang of the diffrent paths in a Character */ function make_path(path,layer, use_shapes, shapegroup){ var masksGroup = null; masksGroup = use_shapes ? layer("ADBE Root Vectors Group") : layer("ADBE Mask Parade"); // Get // PropertyGroup for the shape // or // the PropertyGroup for the masks // masksGroup = layer("ADBE Mask Parade"); if (masksGroup !== null){ var mask = null; // Create a new mask if(shapegroup === null && use_shapes === true){ var pregroup = masksGroup.addProperty("ADBE Vector Group"); pregroup.name = "group";//charname + ' ' + rowname; shapegroup = pregroup.addProperty("ADBE Vectors Group"); mask = shapegroup; } mask = use_shapes ? shapegroup.addProperty("ADBE Vector Shape - Group") : masksGroup.addProperty("ADBE Mask Atom"); // mask = masksGroup.addProperty("ADBE Mask Atom"); if (mask !== null){ mask.name = "path"; // use_shapes ? pathname : charname + ' ' + rowname + ' ' + pathname; // mask.color = maskcolor; var s = new Shape();// new shape object if (s !== null){ s.vertices = path; // The close attribute defaults to true s.closed = false; // put the path verticies into the shape or mask maskShape = use_shapes ? maskShape = mask.property("ADBE Vector Shape") : mask.property("ADBE Mask Shape"); // Change the mask shape (not keyframed) maskShape.setValue(s); } } } // return shapegroup; } /** * Gets the position value at a specific time * It gets shortend to 3 digits float * @param {Layer Object} layer the current layer the get the value from * @param {Number Float} time The curent time * @return {String} builds a string that looks like this: "" + x +" " + y + " "+ z */ function get_pos_values_at_time(layer, time) { // var str = ""; var x = 0.0; var y = 0.0; var z = 0.0; if(layer.parent == null) { x = layer.transform.position.valueAtTime(time, false)[0] - (layer.containingComp.width / 2); y = layer.transform.position.valueAtTime(time, false)[1] - (layer.containingComp.height / 2); } else { x = layer.transform.position.valueAtTime(time, false)[0]; y = layer.transform.position.valueAtTime(time, false)[1]; } if(layer.threeDLayer) { z = layer.transform.position.valueAtTime(time, false)[2]; } else { z = 0.0; }; return [x, y, z]; }; /** * Recursive fetching layer posiitons is cool but does not solve the parenting problem * Wee need to calc the positions a diffrent way * Add a buffer layer with an expression that calcs a parented position toWorld * thnx to the marvelous Paul Tuersley * http://aenhancers.com/viewtopic.php?p=4647 * also saw this @ http://forums.creativecow.net/thread/227/13960 * by the inginious Dan Ebberts * apply to position of buffer layer to get the world position * works 2D and 3D * a = thisComp.layer("parented layer"); * a.toWorld(a.anchorPoint); * * Gets the position of layers * @param {Layer Object} layer The Layer to analys * @param {Number Comp Current Time} time The moment to capture * @param {Layer Object} buffer A NullObject added to the Comp for buffering the positions * @return {NOTHING} Sets a global value. Should return result. Thats better * @todo Remove Global object */ function get_position(layer, time, buffer) { var x = 0; var y = 0; var z = 0; var result = [0, 0, 0]; if(layer.parent != null) { var expr = new Array(); expr.push("// obj-vertex-export parent bake expression thnx 2 Paul T. & Dan E."); expr.push("var sourceLayer = thisComp.layer(" + layer.index + ");"); expr.push("sourceLayer.toWorld(sourceLayer.anchorPoint)"); if(layer.threeDLayer == true) { buffer.threeDLayer = true; } else { buffer.threeDLayer = false; } // buffer.transform.position.expression = ""; buffer.transform.position.expression = expr.join("\n"); result = get_pos_values_at_time(buffer, time); } else { result = get_pos_values_at_time(layer, time); } x = result[0]; y = result[1]; z = result[2]; return [x,y]; // global_curr_pos = [x, y, z]; // }; }// close mpo_import })(this); \ No newline at end of file +/** + * @author fabiantheblind + * @description tries to connect selected layers with a path + * + * + * @todo get also parented position and position with expressions + */ +(function(thisObj){ +// basic panel +mpo_import(thisObj); + + function mpo_import(thisObj){ +// this is global +import_data = { + 'x':10, + 'y':10 +}; + + +/// THIS WILL CHECK IF PANEL IS DOCKABLE OR FLAOTING WINDOW +var win = buildUI(thisObj ); +if ((win !== null) && (win instanceof Window)) { + win.center(); + win.show(); +} // end if win null and not a instance of window + + function buildUI (thisObj ) { + var H = 25; // the height + var W = 30; // the width + var G = 5; // the gutter + var x = G; + var y = G; + var rownum = 1; + var columnnum = 3; + var gutternum = 2; + var win = (thisObj instanceof Panel) ? thisObj : new Window('palette', 'Connect With Path',[0,0,gutternum*G + W*columnnum,gutternum*G + H*rownum],{resizeable: true}); + if (win !== null) { + + // win.check_box = win.add('checkbox',[x,y,x+W*2,y + H],'check'); + // win.check_box.value = metaObject.setting1; + win.do_it_button = win.add('button', [x ,y,x+W*3,y + H], 'connect them'); + // win.up_button = win.add('button', [x + W*5+ G,y,x + W*6,y + H], 'Up'); + + // win.check_box.onClick = function (){ + // alert("check"); + // }; + win.do_it_button.onClick = function () { + connect_all_layers(); + }; + + } + return win; +} + + +function connect_all_layers(){ +// "in function main. From here on it is a straight run" +// + + var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert('please select a comp'); + return; + } + + + if(curComp.selectedLayers.length < 2){ + alert('Please select at least an even number of layer'); + return; + } + + + app.beginUndoGroup('connect-layers'); + var buffer = curComp.layers.addNull(); + buffer.name = "buffer"; + + var layerlist = []; + for(var i = 0; i < curComp.selectedLayers.length;i+=2){ + + var lays = [ curComp.selectedLayers[i] , curComp.selectedLayers[i+1]]; + layerlist.push(lays); + + } + + var shapes = []; + for(var j = 0; j < layerlist.length; j++){ + var global_curr_pos = [0, 0, 0]; + + + var p1 = get_position(layerlist[j][0], curComp.time, buffer);;//layerlist[j][0].transform.position.value; + + // var p2 = get_position(layerlist[j][1], curComp.time, buffer); //layerlist[j][1].transform.position.value; + var n = layerlist[j][0].name + " <-> " +layerlist[j][1].name; + shapes.push(connect(p1 ,p2 , curComp, n)); + } + + for(var k = 0; k < shapes.length;k++){ + shapes[k].selected = true; + } + app.endUndoGroup(); + } + + function connect(pos1, pos2, comp, name){ + var curshape = comp.layers.addShape(); + curshape.name = name; + make_path([ [ pos1[0]- comp.width / 2,pos1[1]- comp.width / 2 ],[ pos2[0] - comp.width / 2,pos2[1] - comp.width / 2 ] ],curshape,true,null); + return curshape; + } + +/** + * Path creation. As always the basis is taken from + * http://www.redefinery.com/ae/fundamentals/ + * + * http://www.redefinery.com/ae/fundamentals/masks/ + * with some additions to fit my needs + * Still... Thanks 2 Jeff Almasol aka redefinery + * + * + * + * this builds a path using ternary operators + * I like it that why a lot. Pretty slick + * http://stackoverflow.com/questions/1771786/question-mark-in-javascript + * + * @param {Array of Arrays} path holds the coordinates for the path + * @param {AVLayer} layer The layer to draw on + * @param {String} rowname This is to sort ot rows + * @param {String} pathname The name of the path + * @param {Array of 3 Values 0 -1 } maskcolor The color of the masks always per Glyph + * @param {ADBE Vectors Group} shapegroup The group that contains the path + * @return {ADBE Vectors Group} for reuse. + * + * @todo Get the hang of the diffrent paths in a Character + */ +function make_path(path,layer, use_shapes, shapegroup){ +var masksGroup = null; + masksGroup = use_shapes ? layer("ADBE Root Vectors Group") : layer("ADBE Mask Parade"); +// Get +// PropertyGroup for the shape +// or +// the PropertyGroup for the masks + // masksGroup = layer("ADBE Mask Parade"); +if (masksGroup !== null){ + var mask = null; +// Create a new mask +if(shapegroup === null && use_shapes === true){ + var pregroup = masksGroup.addProperty("ADBE Vector Group"); + pregroup.name = "group";//charname + ' ' + rowname; + shapegroup = pregroup.addProperty("ADBE Vectors Group"); + mask = shapegroup; + +} + mask = use_shapes ? shapegroup.addProperty("ADBE Vector Shape - Group") : masksGroup.addProperty("ADBE Mask Atom"); + // mask = masksGroup.addProperty("ADBE Mask Atom"); + if (mask !== null){ + mask.name = "path"; // use_shapes ? pathname : charname + ' ' + rowname + ' ' + pathname; + // mask.color = maskcolor; + var s = new Shape();// new shape object + if (s !== null){ + s.vertices = path; + // The close attribute defaults to true + s.closed = false; + // put the path verticies into the shape or mask + maskShape = use_shapes ? maskShape = mask.property("ADBE Vector Shape") : mask.property("ADBE Mask Shape"); + // Change the mask shape (not keyframed) + maskShape.setValue(s); + } + } + } +// return shapegroup; +} + + /** + * Gets the position value at a specific time + * It gets shortend to 3 digits float + * @param {Layer Object} layer the current layer the get the value from + * @param {Number Float} time The curent time + * @return {String} builds a string that looks like this: "" + x +" " + y + " "+ z + */ + + function get_pos_values_at_time(layer, time) { + // var str = ""; + var x = 0.0; + var y = 0.0; + var z = 0.0; + + if(layer.parent == null) { + + x = layer.transform.position.valueAtTime(time, false)[0] - (layer.containingComp.width / 2); + y = layer.transform.position.valueAtTime(time, false)[1] - (layer.containingComp.height / 2); + } else { + x = layer.transform.position.valueAtTime(time, false)[0]; + y = layer.transform.position.valueAtTime(time, false)[1]; + } + + if(layer.threeDLayer) { + z = layer.transform.position.valueAtTime(time, false)[2]; + } else { + z = 0.0; + }; + + return [x, y, z]; + }; + /** + * Recursive fetching layer posiitons is cool but does not solve the parenting problem + * Wee need to calc the positions a diffrent way + * Add a buffer layer with an expression that calcs a parented position toWorld + * thnx to the marvelous Paul Tuersley + * http://aenhancers.com/viewtopic.php?p=4647 + * also saw this @ http://forums.creativecow.net/thread/227/13960 + * by the inginious Dan Ebberts + * apply to position of buffer layer to get the world position + * works 2D and 3D + * a = thisComp.layer("parented layer"); + * a.toWorld(a.anchorPoint); + * + * Gets the position of layers + * @param {Layer Object} layer The Layer to analys + * @param {Number Comp Current Time} time The moment to capture + * @param {Layer Object} buffer A NullObject added to the Comp for buffering the positions + * @return {NOTHING} Sets a global value. Should return result. Thats better + * @todo Remove Global object + */ + + function get_position(layer, time, buffer) { + var x = 0; + var y = 0; + var z = 0; + var result = [0, 0, 0]; + if(layer.parent != null) { + + var expr = new Array(); + expr.push("// obj-vertex-export parent bake expression thnx 2 Paul T. & Dan E."); + expr.push("var sourceLayer = thisComp.layer(" + layer.index + ");"); + expr.push("sourceLayer.toWorld(sourceLayer.anchorPoint)"); + + if(layer.threeDLayer == true) { + buffer.threeDLayer = true; + } else { + buffer.threeDLayer = false; + } + // buffer.transform.position.expression = ""; + buffer.transform.position.expression = expr.join("\n"); + result = get_pos_values_at_time(buffer, time); + } else { + result = get_pos_values_at_time(layer, time); + } + x = result[0]; + y = result[1]; + z = result[2]; + return [x,y]; + // global_curr_pos = [x, y, z]; // + }; + + }// close mpo_import + +})(this); \ No newline at end of file diff --git a/cycle-labels.jsx b/cycle-labels.jsx index 4f668b7..79267fd 100644 --- a/cycle-labels.jsx +++ b/cycle-labels.jsx @@ -1 +1,38 @@ -fun(); function fun(){ app.beginUndoGroup("XXX"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; for(var i = 0; i < curComp.selectedLayers.length;i++){ var lay = curComp.selectedLayers[i]; lay.label = (i+1)%16; } } \ No newline at end of file +/** + * @author fabiantheblind + * @description cycle thru label colors + * this is CS6+ feature I think + * + * @todo [description] + */ +fun(); +function fun(){ + + + +app.beginUndoGroup("XXX"); + + +var curComp = app.project.activeItem; + + if (!curComp || !(curComp instanceof CompItem)){ + + + alert("noComp"); + + return; + + } + + for(var i = 0; i < curComp.selectedLayers.length;i++){ + + + var lay = curComp.selectedLayers[i]; + + + lay.label = (i+1)%16; + + + } + + } \ No newline at end of file diff --git a/disable-expression.jsx b/disable-expression.jsx index eec7a63..4fb35ca 100644 --- a/disable-expression.jsx +++ b/disable-expression.jsx @@ -1 +1,26 @@ -/** * This snippet disables/enables all sellected expressions * */ var curComp = app.project.activeItem; app.beginUndoGroup('disable expression'); for(var i = 0; i < curComp.selectedProperties.length;i++){ var prop = curComp.selectedProperties[i]; if(prop.expressionEnabled === false){ prop.expressionEnabled = true; }else{ //~ prop.expressionEnabled = false; } } app.endUndoGroup(); \ No newline at end of file +/** + * @author fabiantheblind + * @description enable expression + * + * + * @todo [description] + */ +/** + * This snippet disables/enables all sellected expressions + * + */ +var curComp = app.project.activeItem; + app.beginUndoGroup('disable expression'); + +for(var i = 0; i < curComp.selectedProperties.length;i++){ + + var prop = curComp.selectedProperties[i]; + if(prop.expressionEnabled === false){ + prop.expressionEnabled = true; + }else{ +//~ prop.expressionEnabled = false; + } + + + } + app.endUndoGroup(); diff --git a/distort-rotate-at-time.jsx b/distort-rotate-at-time.jsx index aa117d8..35309cd 100644 --- a/distort-rotate-at-time.jsx +++ b/distort-rotate-at-time.jsx @@ -1 +1,23 @@ -/** * This snippet distorts keyframed rotations * The selected prop has to be rotation * */ var curComp = app.project.activeItem; app.beginUndoGroup('rotate'); for(var i = 0; i < curComp.selectedProperties.length;i++){ var plusOrMinus = Math.random() < 0.5 ? -1 : 1; var range = 300; var val = (400 + (range*Math.random())) *plusOrMinus; curComp.selectedProperties[i].setValueAtTime(curComp.time,val); } app.endUndoGroup(); \ No newline at end of file +/** + * @author fabiantheblind + * @description Distord rotation keyframes at a certain time + * + * + * @todo [description] + */ +/** + * This snippet distorts keyframed rotations + * The selected prop has to be rotation + * + */ + + +var curComp = app.project.activeItem; + app.beginUndoGroup('rotate'); +for(var i = 0; i < curComp.selectedProperties.length;i++){ + var plusOrMinus = Math.random() < 0.5 ? -1 : 1; + var range = 300; + var val = (400 + (range*Math.random())) *plusOrMinus; + curComp.selectedProperties[i].setValueAtTime(curComp.time,val); + } + app.endUndoGroup(); diff --git a/duplicate_layer.jsx b/duplicate_layer.jsx index 78aaff9..40bc86e 100644 --- a/duplicate_layer.jsx +++ b/duplicate_layer.jsx @@ -1 +1,27 @@ -fun(); function fun(){ app.beginUndoGroup("XXX"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; var num = 99; for(var i = 0; i < num; i ++){ curComp.selectedLayers[0].duplicate(); } app.endUndoGroup(); } \ No newline at end of file +/** + * @author fabiantheblind + * @description duplicates a layer 99 times + * + * + * @todo [description] + */ +fun(); +function fun(){ + + +app.beginUndoGroup("XXX"); + +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + +var num = 99; + +for(var i = 0; i < num; i ++){ + curComp.selectedLayers[0].duplicate(); + } + +app.endUndoGroup(); +} \ No newline at end of file diff --git a/project_selection_to_grid.jsx b/project_selection_to_grid.jsx index 2889df8..0070719 100644 --- a/project_selection_to_grid.jsx +++ b/project_selection_to_grid.jsx @@ -1 +1,30 @@ -fun(); function fun(){ app.beginUndoGroup("XXX"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; var step= 110; for(var x = step/2; x < curComp.width;x+=step){ for(var y = step/2; y < curComp.height; y+=step){ var nl = curComp.layers.add(app.project.selection[0]); nl.transform.position.setValue([x,y]); } } app.endUndoGroup(); } \ No newline at end of file +/** + * @author fabiantheblind + * @description creates from the selected layer in the project panel a grind in te current comp + * + * + * @todo [description] + */ +fun(); +function fun(){ + + +app.beginUndoGroup("XXX"); + +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + +var step= 110; + + for(var x = step/2; x < curComp.width;x+=step){ + for(var y = step/2; y < curComp.height; y+=step){ + var nl = curComp.layers.add(app.project.selection[0]); + nl.transform.position.setValue([x,y]); + } + } + +app.endUndoGroup(); +} \ No newline at end of file diff --git a/randomOrderSelectedLayers.jsx b/randomOrderSelectedLayers.jsx index c76734e..9e536a4 100644 --- a/randomOrderSelectedLayers.jsx +++ b/randomOrderSelectedLayers.jsx @@ -1 +1,37 @@ -// random order found on: http://forums.creativecow.net/thread/227/10609 // by Dan Ebberts randomOrder(); function randomOrder(){ app.beginUndoGroup("randomOrder selected Layers"); var myComp = app.project.activeItem; var n = myComp.selectedLayers.length; var myLayers = []; var myIdx = []; for (var i = 0; i < n;i++){ myIdx[i] = i; myLayers[i] = myComp.selectedLayers[i]; } var idx; var temp; for (var i = 0; i < myLayers.length;i++){ idx = i + Math.floor(Math.random()*(myIdx.length - i)); temp = myIdx[i]; myIdx[i] = myIdx[idx]; myIdx[idx] = temp; } for (var i = 0; i < myLayers.length;i++){ myLayers[myIdx[i]].moveToBeginning(); } app.endUndoGroup(); } \ No newline at end of file +/** + * @author Dan Ebberts + * @description randomize order of layers + * random order found on: http://forums.creativecow.net/thread/227/10609 + * by Dan Ebberts + * @todo [description] + */ + + +randomOrder(); +function randomOrder(){ + +app.beginUndoGroup("randomOrder selected Layers"); +var myComp = app.project.activeItem; +var n = myComp.selectedLayers.length; +var myLayers = []; +var myIdx = []; +for (var i = 0; i < n;i++){ +myIdx[i] = i; +myLayers[i] = myComp.selectedLayers[i]; +} + +var idx; +var temp; +for (var i = 0; i < myLayers.length;i++){ +idx = i + Math.floor(Math.random()*(myIdx.length - i)); +temp = myIdx[i]; +myIdx[i] = myIdx[idx]; +myIdx[idx] = temp; +} +for (var i = 0; i < myLayers.length;i++){ +myLayers[myIdx[i]].moveToBeginning(); +} + +app.endUndoGroup(); + +} diff --git a/rename-layers-with-padded-number.jsx b/rename-layers-with-padded-number.jsx index 5b2d084..f6f38be 100644 --- a/rename-layers-with-padded-number.jsx +++ b/rename-layers-with-padded-number.jsx @@ -1 +1,30 @@ -fun(); function fun(){ app.beginUndoGroup("rename layers"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; for(var i = 1; i <= curComp.layers.length;i++){ var layer = curComp.layers[i]; layer.name = 'Rohedit_clip ' + String(pad(i,5)); } app.endUndoGroup(); } function pad(num, size) { var s = "00000" + num; return s.substr(s.length-size); } \ No newline at end of file +/** + * @author fabiantheblind + * @description pad all layernames + * + * + * @todo [description] + */ +fun(); +function fun(){ + + +app.beginUndoGroup("rename layers"); + +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + for(var i = 1; i <= curComp.layers.length;i++){ + var layer = curComp.layers[i]; + layer.name = 'Rohedit_clip ' + String(pad(i,5)); + } +app.endUndoGroup(); + +} + +function pad(num, size) { + var s = "00000" + num; + return s.substr(s.length-size); +} \ No newline at end of file diff --git a/rename-layers.jsx b/rename-layers.jsx index 750b3ff..697512a 100644 --- a/rename-layers.jsx +++ b/rename-layers.jsx @@ -1,3 +1,11 @@ +/** + * @author fabiantheblind + * @description rename selected layers with number + * this happens in comp and project panel + * + * + * @todo catch error if layer as no source + */ fun(); function fun(){ @@ -6,7 +14,7 @@ var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; - }; + } diff --git a/select-all-masks-on laayer.jsx b/select-all-masks-on laayer.jsx index 3f98271..a34019d 100644 --- a/select-all-masks-on laayer.jsx +++ b/select-all-masks-on laayer.jsx @@ -1 +1,45 @@ -// given: // layer = Layer object, and the layer can have masks applied // fun(); function fun(){ app.beginUndoGroup("XXX"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; var layer = curComp.selectedLayers[0]; var masksGroup = layer("Masks"); var selectedMasks = new Array(); // Store masks in an array; starts as empty if (masksGroup != null) { // Iterate through properties of masksGroup // Append selected mask to the array for (var i = 1; i <= masksGroup.numProperties; i++) masksGroup.property(i).selected = true; //~ if (masksGroup.property(i).selected) //~ selectedMasks[selectedMasks.length] = masksGroup.property(i); //~ } // The selectedMasks array now contains the list of selected masks // in top-to-bottom order } app.endUndoGroup(); } \ No newline at end of file +/** + * @author redefinery with some edits by fabiantheblind + * @description select all masks on layer + * take a look into the fundamentals + * http://www.redefinery.com/ae/fundamentals/ + * @todo [description] + */ +// given: +// layer = Layer object, and the layer can have masks applied +// +fun(); +function fun(){ + + +app.beginUndoGroup("XXX"); + +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + +var layer = curComp.selectedLayers[0]; + +var masksGroup = layer("Masks"); +var selectedMasks = new Array(); // Store masks in an array; starts as empty +if (masksGroup != null) +{ + // Iterate through properties of masksGroup + // Append selected mask to the array + for (var i = 1; i <= masksGroup.numProperties; i++) + masksGroup.property(i).selected = true; +//~ if (masksGroup.property(i).selected) +//~ selectedMasks[selectedMasks.length] = masksGroup.property(i); +//~ } +// The selectedMasks array now contains the list of selected masks +// in top-to-bottom order + + + + +} +app.endUndoGroup(); + +} \ No newline at end of file diff --git a/set-get-settings.jsx b/set-get-settings.jsx index c7ddc40..c2c512f 100644 --- a/set-get-settings.jsx +++ b/set-get-settings.jsx @@ -1 +1,160 @@ -(function(thisObj){ // Copyright (c) 2013 // Fabian "fabiantheblind" Morón Zirfas // Permission is hereby granted, free of charge, to any // person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to // whom the Software is furnished to do so, subject to // the following conditions: // The above copyright notice and this permission notice // shall be included in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // see also http://www.opensource.org/licenses/mit-license.php // read write settings var data = { settingsSectionName:"testSettings", key_string:"astring", key_int:"ainteger", key_float:"afloatingpointvalue", key_boolean:"aboolean" }; var sc = new SettingsControl(data.settingsSectionName); test_set(); test_get(); sc = null; function test_get () { var resbool = sc.exec.get_setting_boolean( data.key_boolean); alert("Boolean Value: "+resbool); var resint = sc.exec.get_setting_int( data.key_int); alert("Integer Value: "+ resint); var resfloat = sc.exec.get_setting_int( data.key_float); alert("Floating Point Value: "+ resfloat); var resstring = sc.exec.get_setting_string( data.key_string); alert("String Value: "+ resstring); } function test_set(){ sc.exec.set_setting_boolean( data.key_boolean, false); sc.exec.set_setting_number( data.key_int, 345); sc.exec.set_setting_string(data.key_string, "Hello Settings"); sc.exec.set_setting_number(data.key_float, 2.5); } /** * This is a settings control class * Used it at will * @param {String} _section the Settings Section Name */ function SettingsControl (_section) { this.section = _section; this.exec = { section : _section, /** * GETTER functions */ "get_setting" : function (key, variable) { if((app.settings.haveSetting(this.section,key) === true)){ variable = app.settings.getSetting(this.section, key); } return variable; }, "get_setting_int" : function ( key) { var integer = null; integer = this.get_setting( key, integer); if(integer !== null){ integer = parseInt(integer,10); if(isNaN(integer)){ integer = null; } } return integer; }, "get_setting_float" : function ( key) { var floatingpointvalue = null; floatingpointvalue = this.get_setting( key, floatingpointvalue); if(floatingpointvalue !== null){ floatingpointvalue = parseFloat(floatingpointvalue); if(isNaN(floatingpointvalue)){ floatingpointvalue = null; } } return floatingpointvalue; }, "get_setting_boolean" : function ( key) { var bool = null; bool = this.get_setting( key, bool); if(bool !== null){ bool = (bool === 'true') ? true : false; } return bool; }, "get_setting_string" : function ( key) { var str = null; str = this.get_setting( key, str); return str; }, /** * SETTER FUNCTIONS */ "set_setting" : function ( key, val){ app.settings.saveSetting(this.section, key, val); }, "set_setting_number" : function ( key, value) { this.set_setting( key, (String(value)).toLowerCase()); }, "set_setting_string" : function ( key, value) { this.set_setting( key, String(value)); }, set_setting_boolean : function ( key, value) { var val = value ? 'true' : 'false'; this.set_setting( key , (value ? 'true' : 'false')); } }; } })(this); \ No newline at end of file +/** + * @author fabiantheblind + * @description this is a AE Settings Class + * + * + * @todo implement features like Array and Object saving + */ + +(function(thisObj){ + +// Copyright (c) 2013 +// Fabian "fabiantheblind" Morón Zirfas +// Permission is hereby granted, free of charge, to any +// person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to +// whom the Software is furnished to do so, subject to +// the following conditions: +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// see also http://www.opensource.org/licenses/mit-license.php + + +// read write settings + + +var data = { + settingsSectionName:"testSettings", + key_string:"astring", + key_int:"ainteger", + key_float:"afloatingpointvalue", + key_boolean:"aboolean" +}; + +var sc = new SettingsControl(data.settingsSectionName); +test_set(); + +test_get(); + +sc = null; + + +function test_get () { + var resbool = sc.exec.get_setting_boolean( data.key_boolean); + alert("Boolean Value: "+resbool); + + var resint = sc.exec.get_setting_int( data.key_int); + alert("Integer Value: "+ resint); + + var resfloat = sc.exec.get_setting_int( data.key_float); + alert("Floating Point Value: "+ resfloat); + + var resstring = sc.exec.get_setting_string( data.key_string); + alert("String Value: "+ resstring); + +} + +function test_set(){ + sc.exec.set_setting_boolean( data.key_boolean, false); + sc.exec.set_setting_number( data.key_int, 345); + sc.exec.set_setting_string(data.key_string, "Hello Settings"); + sc.exec.set_setting_number(data.key_float, 2.5); +} + + +/** + * This is a settings control class + * Used it at will + * @param {String} _section the Settings Section Name + */ +function SettingsControl (_section) { + this.section = _section; + this.exec = { + section : _section, +/** + * GETTER functions + */ +"get_setting" : function (key, variable) { + if((app.settings.haveSetting(this.section,key) === true)){ + variable = app.settings.getSetting(this.section, key); + } + return variable; +}, + +"get_setting_int" : function ( key) { + var integer = null; + integer = this.get_setting( key, integer); + if(integer !== null){ + integer = parseInt(integer,10); + if(isNaN(integer)){ + integer = null; + } + } + return integer; +}, + +"get_setting_float" : function ( key) { + var floatingpointvalue = null; + floatingpointvalue = this.get_setting( key, floatingpointvalue); + if(floatingpointvalue !== null){ + floatingpointvalue = parseFloat(floatingpointvalue); + if(isNaN(floatingpointvalue)){ + floatingpointvalue = null; + } + } + return floatingpointvalue; +}, + +"get_setting_boolean" : function ( key) { + var bool = null; + bool = this.get_setting( key, bool); + if(bool !== null){ + bool = (bool === 'true') ? true : false; + } + return bool; +}, + +"get_setting_string" : function ( key) { + var str = null; + str = this.get_setting( key, str); + return str; +}, + + +/** + * SETTER FUNCTIONS + */ + + +"set_setting" : function ( key, val){ + app.settings.saveSetting(this.section, key, val); +}, + +"set_setting_number" : function ( key, value) { + this.set_setting( key, (String(value)).toLowerCase()); +}, + +"set_setting_string" : function ( key, value) { + this.set_setting( key, String(value)); +}, + set_setting_boolean : function ( key, value) { + var val = value ? 'true' : 'false'; + this.set_setting( key , (value ? 'true' : 'false')); + } +}; + +} + + +})(this); \ No newline at end of file diff --git a/sort_text_layers_by_content.jsx b/sort_text_layers_by_content.jsx index 5211964..4731839 100644 --- a/sort_text_layers_by_content.jsx +++ b/sort_text_layers_by_content.jsx @@ -1 +1,41 @@ -main(); function main(){ str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; app.beginUndoGroup("XXX"); var curComp = app.project.activeItem; if (!curComp || !(curComp instanceof CompItem)){ alert("noComp"); return; }; var arr = str.split(" "); var layers_to_move = []; for(var i = 0; i < arr.length;i++){ for(var l = 0; l< curComp.selectedLayers.length;l++){ var layer = curComp.selectedLayers[l]; if(arr[i]== layer.text.sourceText.value){ //~ alert("Found " + arr[i] ); layers_to_move.push(layer); break; } } } for(var j = 0; j < layers_to_move.length;j++){ layers_to_move[j].moveToBeginning(); } app.endUndoGroup(); } \ No newline at end of file +/** + * @author fabiantheblind + * @description this sorts layers by their content + * + * + * @todo [description] + */ +main(); +function main(){ +str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + + +app.beginUndoGroup("XXX"); + +var curComp = app.project.activeItem; + if (!curComp || !(curComp instanceof CompItem)){ + alert("noComp"); + return; + } + +var arr = str.split(" "); +var layers_to_move = []; +for(var i = 0; i < arr.length;i++){ + for(var l = 0; l< curComp.selectedLayers.length;l++){ + var layer = curComp.selectedLayers[l]; + if(arr[i]== layer.text.sourceText.value){ +//~ alert("Found " + arr[i] ); + layers_to_move.push(layer); + break; + } + } + } + +for(var j = 0; j < layers_to_move.length;j++){ + layers_to_move[j].moveToBeginning(); + } + +app.endUndoGroup(); + + +} \ No newline at end of file diff --git a/text_to_comp.jsx b/text_to_comp.jsx index 7f83a0c..99a5be0 100644 --- a/text_to_comp.jsx +++ b/text_to_comp.jsx @@ -1,3 +1,11 @@ +/** + * @author fabiantheblind + * @description adds text to a comp with UI + * + * + * @todo check if it works + */ + /** * function template by @author fabiantheblind */ @@ -20,12 +28,12 @@ data = { }; -// THIS WILL CHECK IF PANEL IS DOCKABLE OR FLAOTING WINDOW +// THIS WILL CHECK IF PANEL IS DOCKABLE OR FLAOTING WINDOW var win = buildUI(thisObj ); if ((win !== null) && (win instanceof Window)) { win.center(); win.show(); -} // end if win null and not a instance of window +} // end if win null and not a instance of window function buildUI (thisObj ) { var H = 25; // the height @@ -37,7 +45,7 @@ if ((win !== null) && (win instanceof Window)) { if (win !== null) { win.txt = win.add('edittext',[x ,y,x+W*3,y + H],""); - x+=W*3+G + x+=W*3+G; win.do_it_button = win.add('button', [x ,y,x+W*3,y + H], 'do it'); win.do_it_button.onClick = function () { data.counter++; @@ -49,8 +57,8 @@ if ((win !== null) && (win instanceof Window)) { }; } return win; -} -function run(){ +} +function run(){ // "in function run. From here on it is a straight run" var curComp = app.project.activeItem; @@ -81,7 +89,7 @@ for(var l = 0;l < arrOLayers.length;l++){ layerIndices[layerIndices.length] = arrOLayers[l].index; } -// now precompose the result +// now precompose the result var newComp = curComp.layers.precompose(layerIndices, name, true ); // newComp.parentFolder = folder; // it is the selected layer