Skip to content

Commit

Permalink
fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
stibinator committed May 12, 2021
1 parent 9307811 commit 7418b36
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 487 deletions.
39 changes: 39 additions & 0 deletions (lib)/findBoundingBox.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @target aftereffects
// @include "./LST/LST.js"

function findBoundingBox(theComp, theLayers, useMotion){
// returns the left, right, top and bottom most point of a layer or set of layers in comp space
// if motion is enabled it goes through all the frames looking for the bounding box containing all the motion.
// note that this it calculates the value for the whole layer, even transparent parts.
var bounds = {"unSet": true};
for (var i = 0; i < theLayers.length; i++){
var lyr = theLayers[i];
var currTime = theComp.time;
if (useMotion){
startTime = (lyr.inPoint > 0)? lyr.inPoint: 0;
endTime = (lyr.outPoint < theComp.duration)? lyr.outPoint: theComp.duration;
} else {
startTime = endTime = currTime;
}
for (t = startTime; t <= endTime; t += theComp.frameDuration){
theComp.time = t;
var corners = [[0,0], [lyr.width, 0], [lyr.width, lyr.height], [0, lyr.height]];
for (c=0; c < 4; c++){
var corner = LST.toComp(lyr, corners[c]);
if (bounds.unSet){ //first point, initialise bounds
bounds.left = bounds.right = corner[0];
bounds.top = bounds.bottom = corner[1];
bounds.unSet = false;
} else {
if (corner[0] < bounds.left) bounds.left = corner[0];
if (corner[0] > bounds.right) bounds.right = corner[0];
if (corner[1] < bounds.top) bounds.top = corner[1];
if (corner[1] > bounds.bottom) bounds.bottom = corner[1];
}
}
}
theComp.time = currTime;
}

return bounds;
}
486 changes: 0 additions & 486 deletions ScriptUI Panels/(subtitlesFromSRT_UI.jsx)

This file was deleted.

2 changes: 1 addition & 1 deletion ScriptUI Panels/find-n-replace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ findNReplace.buildUI = function(thisObj) {

var theSearchPattern = (useRegexChkBx.value) ?
new RegExp(patternEditText.text, getFlags()) :
new RegExp(escapeRegexChars(patternEditText.text), getFlags());
new RegExp(findNReplace.escapeRegexChars(patternEditText.text), getFlags());

var changedLayerNames = [];
for (var i = 0; i < theLayers.length; i++) {
Expand Down
223 changes: 223 additions & 0 deletions ScriptUI Panels/linkExpressions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
//@target aftereffects
var thisScript = this;
thisScript.name = "test";
thisScript.sourceSet = thisScript.targetSet = false;

thisScript.buildGUI = function(thisObj) {
// thisObj.theCopiedKeys = thisObj.prefs.readFromPrefs();
thisObj.pal = (thisObj instanceof Panel)?
thisObj:
new Window("palette", thisObj.scriptTitle, undefined, {resizeable: true});
// ----------------------- UI Elements here ---------------------
pal.setExpTargetBtn = thisObj.pal.add("button", [undefined, undefined, 180, 22], "Set Expression Targets");
pal.setExpSourceBtn = thisObj.pal.add("button", [undefined, undefined, 180, 22], "Set Expression Source");
pal.expressionText = thisObj.pal.add("edittext", [undefined, undefined, 180, 128], "No expression set", { multiline: true } );
pal.synchExpressionsBtn = thisObj.pal.add("button", [undefined, undefined, 180, 22], "Update Targets");
pal.synchExpressionsBtn.enabled = false;

pal.setExpSourceBtn.onClick = function () {
thisScript.setExpSource();
pal.synchExpressionsBtn.enabled = (thisScript.sourceSet && thisScript.targetSet);
pal.expressionText.text = thisScript.sourceExp;
};

pal.setExpTargetBtn.onClick = function () {
thisScript.setTargets();
pal.synchExpressionsBtn.enabled = (thisScript.sourceSet && thisScript.targetSet)
};

pal.synchExpressionsBtn.onClick = function () {
thisScript.sourceExp = pal.expressionText.text;
var theLayers = app.project.activeItem.selectedLayers;
if (theLayers.length === 0) {
var compLayers = app.project.activeItem.layers;
for (var i = 1; i <= compLayers.length; i++){
theLayers.push(compLayers[i]);
}
}
// alert(theLayers.length);
thisScript.synchExpressions(theLayers)
};

//------------------------ build the GUI ------------------------
if (thisObj.pal instanceof Window) {
thisObj.pal.center();
thisObj.pal.show();
} else{
thisObj.pal.layout.layout(true);
}
}

//---------------------------- functions n shit ---------------------
thisScript.setExpSource = function(){
var theComp = app.project.activeItem;
thisScript.sourceSet = false;
if (theComp ){
if (theComp.selectedProperties.length) {
var i = 0;
while (theComp.selectedProperties[i] && (! thisScript.sourceSet)){
if (theComp.selectedProperties[i].expressionEnabled){
thisScript.sourceExp = theComp.selectedProperties[i].expression;
thisScript.sourceSet = true;
}
i++;
}
}
}
}

thisScript.setTargets = function(){
thisScript.targetSet = false;
var theComp = app.project.activeItem;
if (theComp) {
var theProps = theComp.selectedProperties;
if (theProps.length > 0) {
for (var i = 0; i < theProps.length; i++){
if (theProps[i].expressionEnabled) {
expressionText = "" + theProps[i].expression;
theProps[i].expression = "//#SynchTarget#\n" + expressionText.replace(/\/\/#SynchTarget#\r\n/, "")
}
}
thisScript.targetSet = true;
}
}
}

thisScript.synchExpressions = function (theLayers) {
app.beginUndoGroup(thisScript.name);
for (var i = 0; i < theLayers.length; i++){
var theProps = getPropertiesWithExpressionsFromLayer(theLayers[i], false);
// alert(theProps.length);
for (var p = 0; p < theProps.length; p++){
if (theProps[p].expressionEnabled){
if (theProps[p].expression.match(/\/\/#SynchTarget#/)) {
theProps[p].expression = "//#SynchTarget#\r\n" + thisScript.sourceExp;
}
}
}
}
app.endUndoGroup;
}



function getPropertiesWithExpressionsFromLayer(theLayer, selectedOnly) {
var props = [];
//only return selected properties. Kinda trivial but here for ease of use
if (selectedOnly) {
for (var j = 0; j < theLayer.selectedProperties.length; j++) {
if (theLayer.selectedProperties[j].expression) {
props.push(theLayer.selectedProperties[j]);
}
}
} else {
for (var p = 1; p <= theLayer.numProperties; p++) {
if (theLayer.property(p)) {
var propertyGroup = theLayer.property(p);
var newProps = traversePropertyGroups(propertyGroup, false);
if (newProps.length) {
for (var i = 0; i < newProps.length; i++) {
if (newProps[i].expressionEnabled) {
props.push(newProps[i]);
}
}
}
}
}
}
return props;
}

function traversePropertyGroups(pGroup, inclusive) {
// walks through property groups, returning properties
// if inclusive is true, returns property groups as well
if (pGroup) {
var props = [];
//alert(pGroup.numProperties);
if (typeof pGroup.numProperties !== 'undefined') {
if (inclusive) {
props.push(pGroup)
}
for (var pp = 1; pp <= pGroup.numProperties; pp++) {
var newProps = traversePropertyGroups(pGroup.property(pp), inclusive);
if (newProps.length) {
for (var i = 0; i < newProps.length; i++) {
props.push(newProps[i]);
}
}
}
} else {
props.push(pGroup);
}
return props;
}
}


//---------------------------- ui prefs -----------------------------
thisScript.Preferences = function(scriptName) {
// look for preferences for this object
// provide a setPref function to allow values to be stored in AE's preferences
// scriptName sets the section of the preference file they are saved in.
this.prefsName = scriptName;
alert ( this.prefsName);
parsePref = function(val, prefType) {
switch (prefType) {
case "integer":
case "int":
return parseInt(val, 10);
case "float":
return parseFloat(val);
case "bool":
return (val === "true")
default:
return val
}
}

this.setPref = function(anObject) {
var currentVal;
if (anObject.name){
if(anObject.hasOwnProperty('value')){
currentVal = anObject.value;
} else if (anObject instanceof EditText){
currentVal = anObject.text;
} else {
throw("objects must have a 'text' or 'value' property to set preferences")
}

if (anObject.savedPref !== currentVal) {
anObject.savedPref = currentVal;
app.settings.saveSetting(this.scriptName, anObject.name, currentVal);
}
}
}

this.getPref = function(anObject){
// constructor
if (anObject.name ){
if (app.settings.haveSetting(this.scriptName, anObject.name)) {
// get prefs for UI control
if (anObject instanceof Slider){
anObject.value = anObject.savedPref = parsePref(app.settings.getSetting(anObject.prefsName, anObject.name), "float");
} else if (anObject instanceof Checkbox || anObject instanceof Radiobutton){
anObject.value = anObject.savedPref = parsePref(app.settings.getSetting(anObject.prefsName, anObject.name), "bool");
} else if (anObject instanceof EditText ){
anObject.text = anObject.savedPref = parsePref(app.settings.getSetting(anObject.prefsName, anObject.name), "string");
} else {
// objects can use specified pref types with the type of the returned result determined by a preftype property
// otherwise the default is a string
anObject.value = anObject.savedPref = anObject.parsePref(app.settings.getSetting(anObject.prefsName, anObject.name), anObject.prefType);
}
}
} else {
throw("objects must have a name to be given prefs.");
}

}

return this;
}

//--------------------- go ahead and run ----------------------
thisScript.buildGUI(this);
49 changes: 49 additions & 0 deletions ScriptUI Panels/mainComp.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//@target aftereffects
var thisScript = this;
thisScript.name = "Main Comp";

thisScript.buildGUI = function(thisObj) {
// thisObj.theCopiedKeys = thisObj.prefs.readFromPrefs();
thisObj.pal = (thisObj instanceof Panel)?
thisObj:
new Window("palette", thisObj.scriptTitle, undefined, {resizeable: true});
// ----------------------- UI Elements here ---------------------
var setMainCompBtn = thisObj.pal.add("button", [undefined, undefined, 180, 22], "Set Main Comp");
var mainCompText = thisObj.pal.add("staticText", [undefined, undefined, 180, 22], "Not set");
var jumpToMainCompBtn = thisObj.pal.add("button", [undefined, undefined, 180, 22], "Jump to Main comp");
jumpToMainCompBtn.enabled = false;

if (app.project.mainComp) {
jumpToMainCompBtn.enabled = true;
mainCompText = app.project.mainComp.name;
}

setMainCompBtn.onClick = function () {
thisScript.setMainComp();
if (app.project.mainComp){
mainCompText.text = app.project.mainComp.name;
jumpToMainCompBtn.enabled = true;
}
};
jumpToMainCompBtn.onClick = function () {
if (app.project.mainComp) {
app.project.mainComp.openInViewer();
}
};

//------------------------ build the GUI ------------------------
if (thisObj.pal instanceof Window) {
thisObj.pal.center();
thisObj.pal.show();
} else{
thisObj.pal.layout.layout(true);
}
}

//---------------------------- functions n shit ---------------------
thisScript.setMainComp = function(){
app.project.mainComp = app.project.activeItem;
}

//--------------------- go ahead and run ----------------------
thisScript.buildGUI(this);
Loading

0 comments on commit 7418b36

Please sign in to comment.