Copy link to clipboard
Copied
Hello,
I am very inexperienced when it comes to scripting.
I've attempted to make an After Effects interface containing a button that when clicked opens a folder that has been created by the script. The command to open the folder works fine, but when I put it in the button function nothing happens. What am I doing wrong? I'm using a Windows workstation.
Here are the essentials of the code:
app.project.close(CloseOptions.DO_NOT_SAVE_CHANGES);
app.newProject();
main();
function main(){
var proj = app.project;
var filePath = "C:\\ScriptUI\\TEST\\subDir\\";
while(Folder(filePath).exists == false){
Folder(filePath).create();
}
//system.callSystem("explorer " + filePath); //this line works and is re-used in a button function on line 30 where it doesn't work
//-------------------------INTERFACE------------------------------
//window and panel creation
var dlg = new Window("dialog", "");
dlg.btnPnl = dlg.add("panel", undefined, "Render finished!");
//buttons
dlg.btnPnl.openBtn = dlg.btnPnl.add("button", undefined, "Open folder");
dlg.btnPnl.closeBtn = dlg.btnPnl.add("button", undefined, "Close");
//just giving the user a visual representation of the file path
var msg = dlg.add("statictext");
msg.text = filePath;
//button functions
dlg.btnPnl.openBtn.onclick = function(){
system.callSystem("explorer " + filePath); //same as line 12 but nothing happens this time
}
dlg.btnPnl.closeBtn.onClick = function(){
dlg.close();
proj.close(CloseOptions.DO_NOT_SAVE_CHANGES);
}
dlg.show();
}
Any hints appreciated
1 Correct answer
Quick fix - it's not onclick, but onClick:
dlg.btnPnl.openBtn.onClick = function () {
// Your magic spells goes here
}
Copy link to clipboard
Copied
Quick fix - it's not onclick, but onClick:
dlg.btnPnl.openBtn.onClick = function () {
// Your magic spells goes here
}
Copy link to clipboard
Copied
!!!
Thanks Tomas! Can't believe I missed that
It works now. Wonderful!
Copy link to clipboard
Copied
Just one note about your script. Change this:
while(Folder(filePath).exists == false){
Folder(filePath).create();
}
to this
if (Folder(filePath).exists === false) {
Folder(filePath).create();
}
It's safer and makes more sense;)
Copy link to clipboard
Copied
Appreciate the input! Will do.
I actually changed it to 'while' just before posting here. I figured it didn't make much sense for me to use 'if' without an 'else' statement. But apparently it doesn't matter.
Again, thanks for the pointer!
Cheers
Copy link to clipboard
Copied
If does its thing if the condition evaluates to true, while does its thing while the condition is true, that is it loops forever as long as the condition is true, which in this case means the script will hang if something stops it creating the folder. If you want to make sure that the folder is created before proceding you could check the return value of the Folder().create function.
Copy link to clipboard
Copied
Hi Stib!
I see... Thanks for clearing that up! Much appreciated.

