Skip to content

Commit

Permalink
Добавлен keyReverse, найден planeResolve, поправлены какие-то ошибки …
Browse files Browse the repository at this point in the history
…и косяки
  • Loading branch information
Nik Ska committed May 25, 2015
1 parent 04183c6 commit f157b3c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion batchChangeTiming.jsx
Original file line number Diff line number Diff line change
@@ -1 +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/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]; 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; } } } 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()
//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/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]; //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()
Expand Down
1 change: 1 addition & 0 deletions changeAllNames.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**Snippet to change target name project-wise.*Comp names and layer names are going to be affected.*I believe there are going to be problems with expressions.*Though I'm not sure**CC-BY, Nik Ska, 2015*/var wrongName = "??";var targetName = "WATWAT";var howMuch = 0;var changeNames = this;changeNames.go = function(wrongName, targetName) { app.beginUndoGroup("Changeallnames"); //1. Disable all expressions changeNames.switchAllExpressions(false, wrongName, targetName); //2. Now change names for(var i = app.project.numItems; i > 0; i--){ var thisItem = app.project.item(i); if(thisItem.name == wrongName){ thisItem.name = targetName; howMuch++; } if(thisItem instanceof CompItem){ for(var c = thisItem.layers.length; c > 0; c--){ var thisLayer = thisItem.layers[c]; if(thisLayer.name == wrongName){ thisLayer.name = targetName; thisLayer.selected = true; thisItem.openInViewer(); howMuch++ } } } } //3. Enable all expressions changeNames.switchAllExpressions(true, '', ''); app.endUndoGroup(); alert("Changed " + String(howMuch) + " names");}changeNames.switchAllExpressions = function(enable, find, replace){ //if enabled == true, enables all expressions. disables otherwise for(var i = app.project.numItems; i > 0; i--){ var thisItem = app.project.item(i); if(thisItem instanceof CompItem){ for(var l = thisItem.layers.length; l > 0; l--){ var thisLayer = thisItem.layers[l]; changeNames.switchExpressions(thisLayer, enable, find, replace); } } }}changeNames.switchExpressions = function(layer, activate, find, replace){ function replaceAll(string, find, replace) { return string.replace(new RegExp(escapeRegExp(find), 'g'), replace); } var enableDisableExpressions = function(_prop, activate, find, replace){ for(var i=1; i<=_prop.numProperties; i++){ var curProp=_prop.property(i); if(curProp instanceof PropertyGroup || curProp instanceof MaskPropertyGroup){ enableDisableExpressions(curProp, activate, find, replace); } else if (curProp.canSetExpression == true){ try{ if(curProp.expressionEnabled == true && activate == false){ curProp.expressionEnabled = false;//выкл } if(curProp.expressionEnabled == false && activate == true){ curProp.expressionEnabled = true;//вкл } if(activate == false){ //replacing target text in expression //when we disable expression curProp.expression = replaceAll(curProp.expression, find, replace); } } catch(err){ null } } } } enableDisableExpressions(layer, activate, find, replace);}changeNames.go(wrongName, targetName);
Expand Down
64 changes: 64 additions & 0 deletions keyReverse.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//ReverseKeys just does what it says is does - reverses keyframes
//Just select a bunch of keyframes and the script will reverse them at the playhead

//CC-BY, Nik Ska, 2015

var reverseKeys = this;

reverseKeys.go = function() {
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
var sel = activeComp.selectedLayers;
if(sel.length > 0){
app.beginUndoGroup("reversing keys");


for(var l = 0; l < sel.length; l++){
thisLayer = sel[l];

if(thisLayer.selectedProperties.length > 0){
for(var p = 0; p < thisLayer.selectedProperties.length; p++){
thisProperty = thisLayer.selectedProperties[p];

//if there are more than 1 keyframes selected
if(thisProperty.selectedKeys.length > 1){
var keys = thisProperty.selectedKeys;


var newKeyTime = activeComp.time;
for (var k = 0; k < keys.length; k++) {

//creating a new key
var newKeyIndex = thisProperty.addKey(newKeyTime);

//getting spatial and temporal ease values
var newKeyInSpatialTangent = thisProperty.keyInSpatialTangent(keys[keys.length - k - 1]);
var newKeyOutSpatialTangent = thisProperty.keyOutSpatialTangent(keys[keys.length - k - 1]);

var newKeyInTemporalEase = thisProperty.keyInTemporalEase(keys[keys.length - k - 1]);
var newKeyOutTemporalEase = thisProperty.keyOutTemporalEase(keys[keys.length - k - 1]);

//setting both value and tangents / easing
thisProperty.setValueAtKey(newKeyIndex, thisProperty.keyValue(keys[keys.length - k - 1]));
thisProperty.setSpatialTangentsAtKey(newKeyIndex, newKeyOutSpatialTangent, newKeyInSpatialTangent)
thisProperty.setTemporalEaseAtKey(newKeyIndex, newKeyOutTemporalEase, newKeyInTemporalEase)

//updating time
if(k < keys.length - 1){
newKeyTime += thisProperty.keyTime(keys[keys.length - k - 1]) - thisProperty.keyTime(keys[keys.length - k - 2]);
}
}
}
}

}
}

app.endUndoGroup();

}
}
}

reverseKeys.go();

34 changes: 34 additions & 0 deletions mixIt.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//MixIt! Remixes layers based on thier position
//CC-BY, Nik Ska, 2015


var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
var sel = activeComp.selectedLayers;
if(sel.length > 0){

app.beginUndoGroup("Remix");
var posArray = [];

//creating anchor point - pos array
for(var s = 0; s < sel.length; s++){
posArray.push([sel[s].property("ADBE Transform Group").property("ADBE Anchor Point").value, sel[s].property("ADBE Transform Group").property("ADBE Position").value]);
}

var i = posArray.length;

while(i > 0){
var rand = parseInt(Math.random()*i); //getting random index

//setting its pos and ap
sel[i-1].property("ADBE Transform Group").property("ADBE Anchor Point").setValue(posArray[rand][0]);
sel[i-1].property("ADBE Transform Group").property("ADBE Position").setValue(posArray[rand][1]);

posArray.splice(rand, 1);

i--;
}

app.endUndoGroup();
}
}
21 changes: 21 additions & 0 deletions planeResolve.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Plane Resolve is a script to find a fourth point based on position of three points
Assumption:
*/

var alpha, beta, gamma, delta;
var A_0, B_0, C_0, D_0, M_0; //initial states
var A, B, C, D, M; //current states
var refFrame = 0;

A =
B =
C =
D =

//Добавить везде _0
var M = [0,0];
M[1] = ((A[1]*(C[0] - A[0])/(C[1] - A[1])) - (B[1]*((D[0] - B[0])/(D[1] - B[1]))) - (A[0] - B[0]))/(((C[0] - A[0])/(C[1] - A[1])) - ((D[0] - B[0])/(D[1] - B[1])));
M[0] = ((M[1] - A[1])/(C[1] - A[1]))*(C[0] - A[0]) + A[0];

0 comments on commit f157b3c

Please sign in to comment.