Calling Functions with ScriptUI
Posted: March 14th, 2012, 2:04 pm
I have written many scripts but cannot seem to overcome the obstacle of ScriptUI. My problems arise when trying to call certain functions with the buttons. Some functions seem to run and some don't. My script was working somewhat earlier today but I cannot figure out what is failing at the moment. Here's my code for what it's worth. It's a script that renders your queued items to a temporary location and then moves them back when finished.
Code: Select all
{
// function MAR_script(thisObj) {
var myPalette = buildUI(this);
if (myPalette != null && myPalette instanceof Window) {
myPalette.show()
}
function buildUI (thisObject) {
if (thisObject instanceof Panel) {
var myWindow = thisObject;
} else {
var myWindow = new Window ("palette", "My Window");
}
//alert( myWindow) ;
myWindow.myPanel = myWindow.add("group");
myWindow.myPanel.orientation = "column";
myWindow.myPanel.titleText = myWindow.myPanel.add("staticText");
myWindow.myPanel.titleText.text = "Move After Render v1.0";
myWindow.myPanel.okButton = myWindow.myPanel.add("button");
myWindow.myPanel.okButton.text = "Render";
myWindow.myPanel.stopButton = myWindow.myPanel.add("button");
myWindow.myPanel.stopButton.text = "Stop Render";
myWindow.myPanel.resetButton = myWindow.myPanel.add("button");
myWindow.myPanel.resetButton.text = "Reset";
myWindow.layout.layout(true);
myWindow.layout.resize();
myWindow.myPanel.okButton.onClick = executeRender;
myWindow.myPanel.resetButton.onClick = function () {
//alert("Cancel");
prefLoad("Temp_Render_Location", 1, true);
//myWindow.close();
}
myWindow.myPanel.stopButton.onClick = function () {
alert("hold your horses there partner, this feature is not yet enabled!");
}
return myWindow;
} //function buildUI ()
function prefLoad(prefLoc,pType, reset){
var curPrefData = ""
if(reset){
curPrefData = "";
}else if(app.settings.haveSetting("BN_Move_File", prefLoc)) {
curPrefData = app.settings.getSetting("BN_Move_File", prefLoc);
}
if(curPrefData){
outData = curPrefData;
//alert("loading " +prefLoc+ " from prefs ="+outData);
}else{
if(pType == 2){//2= file, 1=folder
var findIt = File.openDialog("Please find the file for "+prefLoc, "");
var outData = findIt;
}else{
var findIt = Folder.selectDialog("Please find the location of the folder for "+prefLoc);
var outData = findIt;
}
}
if (app.settings.haveSetting("BN_Move_File", prefLoc)) {
//alert("In savesetting");
app.settings.saveSetting("BN_Move_File", prefLoc, outData.toString());
}else{
app.settings.saveSetting("BN_Move_File", prefLoc, outData.toString());
//alert("In savePrefsAsLong, and string is " + outData.toString());
}
return outData;
}//prefload
function ChangeRenderLocations(){
var tempArray = new Array();
alert(MAR.renderFiles.length +" :start");
//MAR.newLocation = Folder.selectDialog("Select a temporary render output folder...");
MAR.newLocation = prefLoad("Temp_Render_Location", 1, false);
if (MAR.newLocation != null) {
app.beginUndoGroup(MAR.scriptName);
// Process all render queue items whose status is set to Queued.
for (i = 1; i <= app.project.renderQueue.numItems; ++i) {
MAR.curItem = app.project.renderQueue.item(i);
if (MAR.curItem.status == RQItemStatus.QUEUED) {
alert(MAR.curItem.render);
// Change all output modules for the current render queue item.
for (j = 1; j <= MAR.curItem.numOutputModules; ++j) {
MAR.curOM = MAR.curItem.outputModule(j);
MAR.oldLocation = MAR.curOM.file;
//alert(MAR.oldLocation.path);
MAR.curOM.file = new File(MAR.newLocation.toString() + "/" + MAR.oldLocation.name);
tempArray[MAR.fileIndex] = MAR.curOM.file;
MAR.fileIndex++;
//alert("New output path:\n"+MAR.curOM.file.fsName, MAR.scriptName);
}
}
}
app.endUndoGroup();
}
alert(tempArray.length);
return tempArray;
}
function moveFiles(inputFiles){
for(var i = 0; i < inputFiles.length; i++){
MAR.curFile = inputFiles[i];
MAR.curFile.copy(MAR.oldLocation.path +"/" + MAR.curFile.name);
MAR.curFile.remove();
alert("Moved the files from:\n"+ MAR.newLocation.toString() + "\nto\n" + MAR.oldLocation.path);
}
}
function Pow(){
alert("Pow!")
}
function executeRender(){
writeLn("rendering now...");
var MAR = new Object;
MAR.scriptName = "Move File After Render";
//MAR.the_file = File.openDialog("where is the file!?");
writeLn(MAR.scriptName);
MAR.proj = app.project;
writeLn(MAR.proj);
MAR.renderFiles = new Array();
writeLn(MAR.renderFiles.length);
//alert(MAR.renderFiles.length + MAR.fileIndex);
MAR.fileIndex = 0;
writeLn(MAR.renderFiles);
MAR.renderFiles = ChangeRenderLocations();
// MAR.renderFiles = ChangeRenderLocations();
Pow();
MAR.proj.renderQueue.render();
moveFiles(MAR.renderFiles);
//moveFiles(MAR.renderFiles);
//MAR.renderFiles = [];
}
//if(MAR.the_file.copy(MAR.the_folder +"/" + MAR.the_file.name) ){alert("success")};
// }
//MAR_script(this);
}