forked from ae-scripting/scripting-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatchChangeTiming.jsx
142 lines (117 loc) · 4.04 KB
/
batchChangeTiming.jsx
1
//Script used for batch change timing of selected compositions//or actve comp with all layers//It basically adjusts outPoints of all layers and precomps//0.1 - initial release//0.2 - code cleanup, true recursive function//0.3 - minor update//0.31 - fixed improper behavior with shorter than comp layers//0.4 - now you can increase (+) or decrease (-) comp duration//CC-BY-SA, Nik Ska, 2013-2014//http://aescripts.com/authors/m-p/nik-ska/#script "Batch Timing Changer"var chTiming = this;chTiming.version = 0.4;chTiming.scriptTitle = "Batch Timing Changer";chTiming.run = function(){ this.buildGUI(this);}chTiming.buildGUI = function(thisObj){ thisObj.w = (thisObj instanceof Panel) ? thisObj : new Window("palette", thisObj.scriptTitle, undefined, {resizeable:true}); thisObj.w.alignChildren = ['left', 'top'] var g = thisObj.w.add("group{orientation:'row', alignChildren: ['left', 'top']}"); var timeText = g.add("editText", undefined, "0"); timeText.size = [80, 25]; var modeselect = g.add("dropdownlist", undefined, ["s", "fr"]); modeselect.selection = 0; modeselect.size = [42, 25]; var recursiveMode = thisObj.w.add("checkbox", undefined, "Recursive"); recursiveMode.value = true; thisObj.newTime = 0; thisObj.sign = 0; timeText.update = function(){ if(this.text[0]=="-"){ thisObj.sign = -1; } else if(this.text[0]=='+'){ thisObj.sign = 1; } else thisObj.sign = 0; thisObj.newTime = Number(this.text.substr(Math.abs(thisObj.sign),this.text.length)); } timeText.onChanging = function(){ preFilter = /[+-]?([0-9\:]*)/; //this one does not allow to input anything but numbers and some symbols; this.text = this.text.match(preFilter)[0]; /* if(modeselect.selection.index == 0){ var newtxt = this.text.replace(/\:/g, ''); this.text = newtxt.replace(/(\d)(?=(\d\d)+$)/g, '$1:'); //separate with : // str.replace(/(?=(\d\d)+($))/g, '$1:'); } */ } timeText.onEnterKey = function(){ timeText.update(); thisObj.changeTiming(thisObj, thisObj.newTime, thisObj.sign, modeselect.selection.index, recursiveMode.value); } if (thisObj.w instanceof Window){ thisObj.w.center(); thisObj.w.show(); } else thisObj.w.layout.layout(true);}chTiming.changeTiming = function(thisObj, _time, sign, _sel, recursive){ //_time is a new time for a comp //sign is a sign for additional time. -1 for decrease, 0 for change, 1 for increase //_sel is selection type, 0 for frames, 1 for seconds function loopthrough(compToChange, _newDuration){ //first - loop through compositions for(var i = 0; i<compToChange.length; i++){ //now loop through comp's layers for(var k = 1; k<=compToChange[i].layers.length; k++){ var layerToChange = compToChange[i].layers[k]; var unlock = false; //if layer is locked - unlock and lock afterwards if(layerToChange.locked === true){ layerToChange.locked = false; unlock = true; } if(_newDuration>layerToChange.inPoint && layerToChange.outPoint>=compToChange[i].duration){ layerToChange.outPoint = _newDuration; if((layerToChange.source instanceof CompItem) && recursive){ //if the layer we stumble upon is a comp - go deeper loopthrough([layerToChange.source], _newDuration-layerToChange.inPoint); layerToChange.outPoint = _newDuration; } } //lock if(unlock === true){ layerToChange.locked = true; } } compToChange[i].duration = _newDuration; } } var selComps = app.project.selection; var activeComp = app.project.activeItem; if(activeComp && activeComp instanceof CompItem){ //if we are in a comp var comps = [app.project.activeItem]; } else if(selComps.length>0){ var comps = selComps; } if(_sel == 1) _time*=selComps[0].frameDuration //frames if(sign){ //if there is some time involved if(activeComp.duration+_time*thisObj.sign <= 0){ alert("Composition can't be shorter than 0") } else{ _time = activeComp.duration+_time*thisObj.sign; } } app.beginUndoGroup("Change timing"); loopthrough(comps, _time); app.endUndoGroup();}chTiming.run()