From 3870a0f78e26a114ff708afa29b862967cf6a30d Mon Sep 17 00:00:00 2001 From: Jorge Perez Date: Mon, 9 Aug 2021 17:44:50 -0700 Subject: [PATCH] Updated repository with latest 'live' tools. --- ScriptUI Panels/BaseScriptsUIPanel.jsx | 18 ++-- main.jsx | 114 +++++++++++++++++++++-- usefulFunctions.jsx | 119 +++++++++++++++++++++++++ y.jsx | 81 ++++++++++++++++- y_AFXExtensions.jsx | 26 ++++++ y_CompHerder.jsx | 1 + y_JSExtensions.jsx | 11 +++ 7 files changed, 351 insertions(+), 19 deletions(-) create mode 100644 usefulFunctions.jsx create mode 100644 y_AFXExtensions.jsx create mode 100644 y_CompHerder.jsx create mode 100644 y_JSExtensions.jsx diff --git a/ScriptUI Panels/BaseScriptsUIPanel.jsx b/ScriptUI Panels/BaseScriptsUIPanel.jsx index 996053e..f14ab51 100644 --- a/ScriptUI Panels/BaseScriptsUIPanel.jsx +++ b/ScriptUI Panels/BaseScriptsUIPanel.jsx @@ -30,13 +30,13 @@ myButtonGroup.alignChildren = "center"; win.button1.onClick = function(){ - button1Click(); + win.button1Click(); } win.button2.onClick = function(){ - button2Click(); + win.button2Click(); } win.button3.onClick = function(){ - button3Click(); + win.button3Click(); } win.layout.layout(true); @@ -57,14 +57,14 @@ /* General functions */ /* Project Specific functions */ - function button1Click(){ - alert("Button 1 was clicked"); + w.button1Click = function(){ + alert( w.button1.text + "was clicked"); //reference panel stuff } - function button2Click(){ - alert("Button 2 was clicked"); + w.button2Click =function(){ + alert( w.button2.text + "was clicked"); } - function button3Click(){ - alert("Button 3 was clicked"); + w.button3Click = function(){ + alert( w.button3.text + "was clicked"); } diff --git a/main.jsx b/main.jsx index f20a38c..c49c20e 100644 --- a/main.jsx +++ b/main.jsx @@ -1,20 +1,116 @@ #include "y.jsx"; -my_comps = getSelectedProjectItems(); -var my_comp = getSelectedProjectItems()[0]; -// new_size = [ 240,320 ]; -//new_size = [ 4096, 2048 ]; +function compareComps( compA, compB, precision ){ + // 0 = basic , 1 = advanced , 2 = certain + var result = false; + if ( precision == 0){ + propList = ["name","width","height","frameDuration","numLayers"]; + alert(propList); + } + for ( property in compA ){ + + for ( var i = 0 ; i < propList.length ; i++ ){ + if ( property == propList[i] ){ + //alert( property + String(compA[property]) + "/" + String(compB[property]) + " : " + ( compA[property] == compB[property]) ); + if ( compA[property] == compB[property] ){ + result = true; + }else{ + result = false; + return result; + } + + } + } + + } + return result +} +function isSourceOneOfThese( layer , sourcesArray){ + for ( var p = 0 ; p < sourcesArray.length ; p++ ){ + if ( layer.source == sourcesArray[p] ){ + return true + } + } + return false +} +function consolidateSelectedComps(){ + app.beginUndoGroup("Consolidate Selected Comps"); + //DANGER Comps might not be the same, they only have to be NAMED the same. + var allCompItems = getAllProjectComps(); + var myItems = getSelectedProjectComps(); + // var allMyItems = []+myItems; + var newSource = myItems.pop(); + + for ( var i = 0 ; i < allCompItems.length ; i ++){ + var curComp = allCompItems[i]; + for ( var l = 1 ; l <= curComp.layers.length ; l ++){ + + var curLayer = curComp.layers[l]; + //alert(newSource); + //alert(myItems); + + if ( isSourceOneOfThese( curLayer , myItems )){ + if( curLayer.source != newSource ){ + curLayer.replaceSource(newSource,true); + } + } + } + } + for ( var i = 0 ; i < myItems.length ; i ++){ + var myItem = myItems[i]; + myItem.remove(); + } + app.endUndoGroup(); +} + +// var myItems = getSelectedProjectComps(); +// var myLayer = app.project.activeItem.selectedLayers[0] +// alert(isSourceOneOfThese(myLayer, myItems)) +//alert(compareComps( myItems[0], myItems[1], 0)); + +consolidateSelectedComps(); + +// a = app.project.items[1]; +// b = app.project.items[2]; +// // alert(a.frameDuration) +// // alert(b) +// var same = compareComps( a, b, 0 ); +// alert(same); + +// for ( property in a ){ +// alert( property ); +// } +//my_comps = getSelectedProjectItems(); +//var myLayers = app.project.activeItem.selectedLayers; +//var my_comp = getSelectedProjectItems()[0]; + +//zeroOutLayer(myLayers[0]); + +//app.project.save(); +//alert(); + +//resizeCompsCanvasCentered( [ 1080, 1080 ] , true ); //1x1 +//resizeCompsCanvasCentered( [ 1080, 1350 ] , true ); //4x5 +//resizeCompsCanvasCentered( [ 1080, 1920 ] , true ); + +//a="WTC2_1x1_TUNG_GLD_ROTO_Ghostface_02tl_03jvFIN" +//alert( insertAt( a, "TXT", -12 )); + +//insertAtSelectedItemsNames( "TXT", -12 ); // insert "TXT" into the 12th position from the end of all selected Items' names. +//insertAtSelectedItemsNames( "ROTO", -12 ); +//insertAtSelectedItemsNames( "TXTLS", -12 ); //setFPS( my_comp, 24 ); +//setCompsFPS( 12 ); -for ( var i = 0 ; i < my_comps.length ; i++ ){ - var my_comp = my_comps[i]; - setFPS( my_comp, 24 ); -} +//new_size = [ 4096, 2048 ]; //selectLayersByParented( false ); //resizeCompCanvasCentered( my_comp, new_size, true ) -//alert(system.callSystem("whoami")) \ No newline at end of file + +//alert(system.callSystem("whoami")) + +//app.project.save() \ No newline at end of file diff --git a/usefulFunctions.jsx b/usefulFunctions.jsx new file mode 100644 index 0000000..cb679a5 --- /dev/null +++ b/usefulFunctions.jsx @@ -0,0 +1,119 @@ +#include "y_JSExtensions.jsx"; +function sortNumber(a,b){ +return a - b; +} +function pad(n,i){ //pad n with ceroes up to i places. + if (String(n).length>=i){ + return String(n) + }else{ + dif = i- (String(n)).length; + padding = ""; + for (p=0;p1){ + for(L=0;L<_lines.length;L++){ + alert(_lines[L]); + if(L==_lines.length-1||_lines[L]==''){ + dash = ''; + }else{ + dash = '.'; + } + if(_lines[L]!=''){ + newStr = newStr+_lines[L]+dash; + }else{ + newStr = newStr; + } + } + }else{ + newStr = _str; + } + return newStr; +} +function yFactor(n,f){ + if((typeof(n)=='number'&&typeof(f)=='number')&&(n>f)){ + value = n - (n%f); + return(value); + }else{ + alert('error'); + } +} diff --git a/y.jsx b/y.jsx index 3be4b56..d502b0b 100644 --- a/y.jsx +++ b/y.jsx @@ -10,6 +10,30 @@ function getSelectedProjectItems(){ } return items; } +function getSelectedProjectComps(){ + var items = []; + var p = app.project; + for ( var i = 1 ; i <= p.numItems ; i ++ ){ + var item = p.item(i); + if ( (item.selected) && (item.typeName == "Composition") ){ + items.push(item); + } + } + return items; +} + +function getAllProjectComps(){ + var items = []; + var p = app.project; + for ( var i = 1 ; i <= p.numItems ; i ++ ){ + var item = p.item(i); + if ( item.typeName == "Composition" ){ + items.push(item); + } + } + return items; +} + function selectLayersByParented( isParented ){ layersToSelect = getLayersByParented( isParented ); for ( var i = 0; i < layersToSelect.length; i ++ ){ @@ -18,6 +42,10 @@ function selectLayersByParented( isParented ){ } } function getLayersByParented( isParented ){ + + /* TODO + not use activeItem. but have the function take a comp as an argument, to avoid activItem becoming obsolete. + */ var active_comp = app.project.activeItem; var filtered_layers = []; @@ -52,7 +80,7 @@ function setDurationInFrames( myComp, newFrameDuration ){ //myComp. }; function resizeCompCanvasCentered( my_comp, new_size, keep_scaler ){ - app.beginUndoGroup("Resize Comp Canvas Centered") + //app.beginUndoGroup("Resize Comp Canvas Centered") var n = my_comp.layers.addNull(); //center null on actual comp size @@ -79,5 +107,56 @@ function resizeCompCanvasCentered( my_comp, new_size, keep_scaler ){ }else{ n.remove() } + //app.endUndoGroup(); +} + +function resizeCompsCanvasCentered( new_size, keep_scaler ){ + app.beginUndoGroup("Resize Comps' Canvas Centered") + var my_comps = getSelectedProjectItems(); + for ( var i = 0 ; i < my_comps.length ; i ++ ){ + var my_comp = my_comps[i]; + //alert( my_comp.name ) + resizeCompCanvasCentered( my_comp, new_size, true ); + } + app.endUndoGroup(); +} + +function setCompsFPS( newFPS ){ + app.beginUndoGroup("Change selected Comps' framerates"); + var my_comps = getSelectedProjectItems(); + for ( var i = 0 ; i < my_comps.length ; i++ ){ + var my_comp = my_comps[i]; + setFPS( my_comp, 8 ); + } app.endUndoGroup(); +} + +function zeroOutLayer( myLayer ){ + myLayer.position.setValue([0,0]); + myLayer.rotation.setValue(0); + myLayer.anchorPoint.setValue([0,0]); + myLayer.scale.setValue([100,100]); +} + +function insertAt( text , insertText, pos ){ + var myText = text; + var insertText = insertText; + var myPos = pos; + var newText; + if( myPos >= 0 ){ + newText= myText.substr(0,myPos)+"_"+insertText+myText.substr(myPos); + }else{ + newText= myText.substr(0,myText.length+myPos)+insertText+"_"+myText.substr(myText.length+myPos); + } + return newText +} + +/* Extra for renaming tool, insert stringA +into specified position of stringB.*/ +function insertAtSelectedItemsNames( text, pos){ + my_comps = getSelectedProjectItems(); + for ( var i = 0; i < my_comps.length ; i ++ ){ + var myComp = my_comps[i]; + myComp.name = insertAt( myComp.name , text, pos); + } } \ No newline at end of file diff --git a/y_AFXExtensions.jsx b/y_AFXExtensions.jsx new file mode 100644 index 0000000..6d627b6 --- /dev/null +++ b/y_AFXExtensions.jsx @@ -0,0 +1,26 @@ +//Useful extensions to AFX Extendscript classes. + +if (AVLayer.prototype. getPins==null) AVLayer.prototype. getPins=function(){ //Extends the AVLayer class with the getPinsfunctions which returns the Layer's property groups which are pins. + this.selectedPins = []; + for(prop=0;prop