Hi Guys,
I'm trying to set up a script that will allow me to specify a number range (1-144/5-11 etc) after selecting a comp. The script will then duplicate that comp filling in the text layer with the numbers as it goes through the range before sending the new comps to the renders queue. So what I should get out of it at the end is 144 comps (& renders) with the text layer changed in each to the sequential numbers in the range specified.
I have tried to edit a script from an FXPHD class by John Montgomery but I just can't seem to crack it. My attempt is pasted below but I'm too much of a newbie at this to get my head around it. Any help would be fantastic. The debugger tells me that var numberItems = myLastNumString; is not defined, but I'm trying to get the last number in the range to append to this???
//script by John Montgomery, copyright 2007 fxphd, Pty Ltd
//portions from Byron Nash, Snap5 http://www.snap5.tv and Dan Ebberts http://www.motionscript.com
//Modify the following settings for your use
var filePath = "/Volumes/PoudreVault/renders";
var myTemplate = "Lossless with Alpha";
var myFile = "/[compName].mov";
//End modify
var mySelection = app.project.selection;
var numberItems = myLastNumString;
if (mySelection == null){
alert("Please establish a comp as the selected item and run the script again");
} else {
app.beginUndoGroup("Create Number Array");
if ( ShowDialog() == 1 ) {
for (var i = 0; i < numberItems; i++) {
// create new comp named after text entry
var myComp = mySelection.duplicate();
var compName = mySelection.name + "-" + i;
if (compName.length > 30){
var compNameShort = compName.slice(0,29);
myComp.name = compNameShort;
}else{
myComp.name = compName;
}
//update text in comp based upon entry from user
//set name
var nameLayer = myComp.layer(1);
nameLayer.property("Source Text").setValue("Lot "+ i);
app.project.renderQueue.items.add(myComp);
//get number of items in Render Queue -- we want to get the one we just added so we can change it
myRenderItem = app.project.renderQueue.numItems;
//set to template
app.project.renderQueue.item(myRenderItem).outputModules[1].applyTemplate(myTemplate);
//set output file name
app.project.renderQueue.item(myRenderItem).outputModules[1].file = new File(filePath + myFile);
}
}
app.endUndoGroup();
//Show the render queue
app.project.renderQueue.showWindow(true);
//Render that baby
app.project.renderQueue.render();
}
function myFirstNumStringValue() {
myFirstNumString = this.text
}
function myLastNumStringValue() {
myLastNumString = this.text
}
function ShowDialog()
{
var my_dialog = new Window("dialog","Enter Number Array");
my_dialog.bounds = [200,200,450,410];
my_dialog.add("statictext", [10, 10, 250, 30], "Enter first and last numbers ");
//Field for first number input -- then assigns variable
var firstNumInput = my_dialog.add("edittext", [30, 30, 240, 50], "First #");
firstNumInput.onChange = myFirstNumStringValue;
//Field for last number input -- then assigns variable
var lastNumInput = my_dialog.add("edittext", [30, 60, 240, 80], "Last #");
lastNumInput.onChange = myLastNumStringValue;
okButtton = my_dialog.add("button", [10, 100, 120, 120], "OK", {name:'ok'} );
cancelButton = my_dialog.add("button", [130,100, 240, 120], "Cancel", {name:'cancel'});
// display the dialog.
return my_dialog.show();
}
Automated text replacement
Moderator: Paul Tuersley
- lloydalvarez
- Enhancement master
- Posts: 460
- Joined: June 17th, 2004, 9:27 am
- Location: New York City, NY
- Contact:
You need to return the values you want from the function before you can call them in your main code.
-Lloyd
This should work:
-Lloyd
This should work:
Code: Select all
//script by John Montgomery, copyright 2007 fxphd, Pty Ltd
//portions from Byron Nash, Snap5 http://www.snap5.tv and Dan Ebberts http://www.motionscript.com
//Modify the following settings for your use
var filePath = "/Volumes/PoudreVault/renders";
var myTemplate = "Lossless with Alpha";
var myFile = "/[compName].mov";
//End modify
var mySelection = app.project.selection;
if (mySelection.length != 1){
alert("Please establish a comp as the selected item and run the script again");
} else {
app.beginUndoGroup("Create Number Array");
var dlg = ShowDialog();
var showDlg = dlg[0].show();
if (showDlg == 1 ) {
var firstNum = parseInt(dlg[1].text,10);
var lastNum = parseInt(dlg[2].text,10);
//var numberItems = lastNum - firstNum ;
for (var i = firstNum; i <= lastNum; i++) {
// create new comp named after text entry
var myComp = mySelection[0].duplicate();
var compName = mySelection[0].name + "-" + i;
if (compName.length > 30){
var compNameShort = compName.slice(0,29);
myComp.name = compNameShort;
}else{
myComp.name = compName;
}
//update text in comp based upon entry from user
//set name
var nameLayer = myComp.layer(1);
nameLayer.property("Source Text").setValue("Lot "+ i);
app.project.renderQueue.items.add(myComp);
//get number of items in Render Queue -- we want to get the one we just added so we can change it
myRenderItem = app.project.renderQueue.numItems;
//set to template
app.project.renderQueue.item(myRenderItem).outputModules[1].applyTemplate(myTemplate);
//set output file name
app.project.renderQueue.item(myRenderItem).outputModules[1].file = new File(filePath + myFile);
}
}
app.endUndoGroup();
//Show the render queue
app.project.renderQueue.showWindow(true);
//Render that baby
app.project.renderQueue.render();
}
function myFirstNumStringValue() {
myFirstNumString = this.text
}
function myLastNumStringValue() {
myLastNumString = this.text
}
function ShowDialog()
{
var my_dialog = new Window("dialog","Enter Number Array");
my_dialog.bounds = [200,200,450,410];
my_dialog.add("statictext", [10, 10, 250, 30], "Enter first and last numbers ");
//Field for first number input -- then assigns variable
var firstNumInput = my_dialog.add("edittext", [30, 30, 240, 50], "First #");
firstNumInput.onChange = myFirstNumStringValue;
//Field for last number input -- then assigns variable
var lastNumInput = my_dialog.add("edittext", [30, 60, 240, 80], "Last #");
lastNumInput.onChange = myLastNumStringValue;
okButtton = my_dialog.add("button", [10, 100, 120, 120], "OK", {name:'ok'} );
cancelButton = my_dialog.add("button", [130,100, 240, 120], "Cancel", {name:'cancel'});
// display the dialog..
return [my_dialog,firstNumInput,lastNumInput];
}