David Conklin
Forum Replies Created
-
David Conklin
March 3, 2016 at 6:11 pm in reply to: Checkbox to select X value or Y Value of a LayerSomething like this should work.
Change the 2 variables at the top to point to your Layer and Checkbox controls. This expression will output the X-Value of the Layer Control Layer if the box is un-ticked, and the Y-Value if it is ticked.
var lyrControl = thisLayer("Effects")("Layer Control")("Layer");
var chkbxControl = thisLayer("Effects")("Checkbox Control")("Checkbox");if(!chkbxControl.value){
lyrControl.position[0]; // use X-position.
} else {
lyrControl.position[1]; // use Y-Position
}David Conklin
Motion Designer -
David Conklin
March 3, 2016 at 5:03 pm in reply to: Keep expressions intact when moving a control layer to another compSomething I forgot to add, is that you’ll need to change line 31 and 34, ‘topComp.layer(“Controller”)’ to the name of your controller. If your control layer is just named ‘null’, you’d change them to ‘topComp.layer(“null”)’.
Best of luck!
David Conklin
Motion Designer -
David Conklin
March 3, 2016 at 4:55 pm in reply to: Keep expressions intact when moving a control layer to another compHey there,
This solution is not super straightforward, but also not that complicated. ESTK provides a handy little app.project.autoFixExpression(oldText, newText) command, that you can use to batch-fix expressions. This is the main thing you’re looking for.
The issue is, autoFixExpressions will only fix expressions that YOUR SCRIPT causes to break, not preexisting errors. So, in the script here’s what we do.
1. Make variables that have the names of the comps we need (the controller comp, the pre-comp, and the new comp).
2. Find these comps.
3. Copy controller from the controller (‘top’) comp, to the new comp.
4. Remove controller from top comp, thereby breaking the expression.
5. run .autoFixExpressions(topCompName, newCompName) to fix the expressions.Here’s the script. Hope it helps!
(function fixExpressions(){
app.beginUndoGroup("Fix expressions.");var proj = app.project
var topCompName = "Top Comp"; // comp where controller lives now.
var preCompName = "Pre-Comp"; // comp where expressions are (that break).
var newCompName = "Another Comp"; // comp you want the controller in.// holders for comps.
var topComp,preComp,newComp;// loop through project and get the comps.
for (var i = 1; i <= proj.numItems; ++i){
switch(proj.item(i).name){
case topCompName:
topComp = proj.item(i);
break;
case preCompName:
preComp = proj.item(i);
break;
case newCompName:
newComp = proj.item(i);
break;
default:
break;
}
}// move controller
topComp.layer("Controller").copyToComp(newComp);// delete from old comp.
topComp.layer("Controller").remove();// fix expressions
proj.autoFixExpressions(topCompName,newCompName);app.endUndoGroup();
})();David Conklin
Motion Designer -
David Conklin
March 3, 2016 at 4:15 pm in reply to: Change compositions names with text from external fileHey there, sorry for misunderstanding.
A quick change on line 28 should do what you want (with also reading from the same slash-split external file).
In general, if you want to rename some project items, you can do it like this:
(function renameProjectItems(){var proj = app.project;
var searchName = "Clip1";
var newName = "This is the first text video";for (var i = 1; i <= proj.numItems; ++i){
if (proj.item(i).name == searchName){
proj.item(i).name = newName
}
}})();
You basically loop through all the project items until you find one that has the same name as the ‘searchName’ var, then change that item’s name to the value of newName.
Here’s the updated script, which should now change the name of the comp, rather than the text layer inside of the comp:
(function renameItemsFromFile(){app.beginUndoGroup("Rename items from file.");
// request file.
var myFile = File.openDialog("Select the file."); // get the file.
if (myFile != null){ // check that file was selected.
var fileOK = myFile.open("r"); // open the file in read mode.
if(fileOK){ // make sure we can read the file.var proj = app.project; // the current project.
if (!proj) return alert("Please have an after effects file open!");var curLn; // holder for current line.
while(!myFile.eof){ // check that we're not at the end.
curLn = myFile.readln(); // read current line.if (curLn == "") { curLn == "\r" } // line's empty. skip.
curLn = curLn.split("/"); // break line at slash.
cmp = curLn[0]; // the part before the slash.
txt = curLn[1]; // the part after the slash.for (var i = 1; i <= proj.numItems; ++i){ // loop through all project items
if(proj.item(i).name == cmp){ // comp name matches.
proj.item(i).name = txt; // Change text.
}
}}
}
}app.endUndoGroup();
})();
My text file (still) looks like this:
Text1/This is the first text.
Text2/This is the second text.
Text3/This is the third text.
Clip1/This is the first text video.
Clip2/This is the second text video.
Clip3/This is the third text video.David Conklin
Motion Designer -
David Conklin
March 2, 2016 at 6:55 pm in reply to: Change compositions names with text from external fileAlso, giving credit where credit is due: the majority of this code is lifted directly from Dan’s fantastic case study on reading an external text file on motion script. I’d highly recommend checking it out as he is more thorough than I have been here.
David Conklin
Motion Designer -
David Conklin
March 2, 2016 at 6:52 pm in reply to: Change compositions names with text from external fileHello friend,
Reading text from an external file is somewhat tricky, especially if you want to treat that text as javascript code and not raw text data. I have a solution for you, but it involves slightly re-structuring your text file. If you are desperate for a text file that has javascript inside of it, you can check out JSON parsing. Lloyd Alverez did a good tutorial about parsing JSON if you want to check that out.
Anyway, if you structure your text file with a ‘split’ character, which differentiates the comp name from the text to change, you can have your script extract 2 pieces of data from that single line. I’ve created a test text file which does this, following the ‘Comp Name/Text Content’ format. Keep in mind, that I am using the “/” character here to split, so this won’t work if your text or comp name has a slash in it.
Text file looks like this:
Text1/This is the first text.
Text2/This is the second text.
Text3/This is the third text.
Clip1/This is the first text video.
Clip2/This is the second text video.
Clip3/This is the third text video.And we can use a script to split each of those lines. The script then finds a comp that has the same name as the pre-/ part of the line, and changes it’s text layer’s text to be the post-/ part.
Disclaimer: this was written for only testing purposes. It does not have fallbacks for if you have 2 comps named the same thing or if it can’t find a comp. It also assumes each comp has only 1 layer and that layer is a text layer. With a few tweaks, though, you should be able to make it work in a production environment.
The script:
(function renameItemsFromFile(){app.beginUndoGroup("Rename items from file.");
// request file.
var myFile = File.openDialog("Select the file."); // get the file.
if (myFile != null){ // check that file was selected.
var fileOK = myFile.open("r"); // open the file in read mode.
if(fileOK){ // make sure we can read the file.var proj = app.project; // the current project.
if (!proj) return alert("Please have an after effects file open!");var curLn; // holder for current line.
while(!myFile.eof){ // check that we're not at the end.
curLn = myFile.readln(); // read current line.if (curLn == "") { curLn == "\r" } // line's empty. skip.
curLn = curLn.split("/"); // break line at slash.
cmp = curLn[0]; // the part before the slash.
txt = curLn[1]; // the part after the slash.for (var i = 1; i <= proj.numItems; ++i){ // loop through all project items
if(proj.item(i).name == cmp){ // comp name matches.
proj.item(i).layer(1).text.sourceText.setValue(txt); // Change text.
}
}}
}
}app.endUndoGroup();
})();
Best of luck!
David Conklin
Motion Designer -
A bit of an update.. upon running this script via the Window menu in CS6, the red X button responds appropriately, though clicking the close button still does nothing. Any additional thoughts on this?
David Conklin
Motion Designer -
Try this. This animates between 2 keyframes and adds a random amount to the second keyframe. You can change the randX and randY variables to fit whatever ranges you want (will pick a random # between the 2 in parentheses).
The only note, this random # is being generated based on the index of your layer, meaning two layers in different comps will have the same random if they have the same index. All layers inside a single comp, though, should be entirely random.
Hope this is helpful!
try{
seedRandom(index, true);
var randY = gaussRandom(0, 100);
var randX = gaussRandom(0, 100);var key1Time = thisProperty.key(1).time;
var key2Time = thisProperty.key(2).time;
var key3Time = thisProperty.key(3).time;var key1Val = thisProperty.key(1).value;
var key2Val = thisProperty.key(2).value + [randX, randY];
var key3Val = thisProperty.key(3).value;if (time > key1Time && time < key2Time){ ease(time, key1Time, key2Time, key1Val, key2Val); } else if (time < key3Time) { ease(time, key2Time, key3Time, key2Val, key3Val); } else { value; } } catch(e){ value; }
David Conklin
Motion Designer -
Heya. Try this guy. The decimals during the incrimination were causing some problems, this just rounds the numbers. Sorry about that.
function formatNumber (num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
}
var beginTime = 0; //time to start counting (seconds)
var finishTime = 60; //time to finish countint (secs)
var beginVal = 301; //first number;
var finishVal = 215000000; //end number
var anim = ease(time, beginTime, finishTime, beginVal, finishVal)
formatNumber(Math.round(anim));David Conklin
Motion Designer -
You can use the below expression on the source text property of a text layer. There are four variables you can change to suit your purposes. The values I’m gving you count from 301 to 215,000,000 over 60 seconds. Remember that even in a whole minute there are not 215 billion frames, so your steps per frame will be quite large.
The function ‘formatTime’ is what adds the commas. It is taken from this site: https://blog.tompawlak.org/number-currency-formatting-javascript – You should check it out for more info on how it works.
function formatNumber (num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
}
var beginTime = 0; //time to start counting (seconds)
var finishTime = 60; //time to finish countint (secs)
var beginVal = 301; //first number;
var finishVal = 215000000; //end number
formatNumber(ease(time, beginTime, finishTime, beginVal, finishVal));David Conklin
Motion Designer