0

I have a dialogue box that allows the user to browse for one PSD file and then to browse for multiple TIF files. When browsing for multiple TIF files, the text in the edittext box comes out as undefined. Where as, if I just remove the ability to select multiple files, it works.

var dlg = new Window('dialog', 'PSD Creator', [100, 100, 500, 550] );  

dlg.pnl_browse = dlg.add('panel', [10, 10, 390, 150], 'Browse');
    dlg.pnl_browse.txt_staticPSD = dlg.pnl_browse.add('statictext' , [15, 10, 375, 30],'Select the project images folder:');
    dlg.pnl_browse.btn_browsePSD = dlg.pnl_browse.add ('button', [15, 35, 60, 60], '...');
    dlg.pnl_browse.txt_editPSD = dlg.pnl_browse.add('edittext' , [65, 35, 365, 55],'<Select the project images folder>');
    dlg.pnl_browse.txt_staticTIFF = dlg.pnl_browse.add('statictext' , [15, 70, 375, 90],'Select the folder where you TIFF images are:');
    dlg.pnl_browse.btn_browseTIFF = dlg.pnl_browse.add ('button', [15, 95, 60, 120], '...');
    dlg.pnl_browse.txt_editTIFF = dlg.pnl_browse.add('edittext' , [65, 95, 365, 120],'<Select the folder where you TIFF images are>');    

dlg.btn_ok = dlg.add ('button', [70,400,190,430], 'ok');
dlg.btn_cancel = dlg.add ('button', [210,400,320,430], 'cancel');


dlg.pnl_browse.btn_browsePSD.onClick = function ()  {   
    selectFilePSD = File.openDialog("Please select your template file.","*.psd");   
        if(selectFilePSD != null) dlg.pnl_browse.txt_editPSD.text =  decodeURI(selectFilePSD.fsName); 
}


dlg.pnl_browse.btn_browseTIFF.onClick = function ()  {   
    selectFileTIFF = File.openDialog("Please select your tiff images.","*.TIF; *TFF", true);  
        if(selectFileTIFF != null) dlg.pnl_browse.txt_editTIFF.text =  decodeURI(selectFileTIFF.fsName); 
 }       

dlg.btn_ok.onClick = function () {

        dlg.close()
        open (selectFilePSD);
        open (selectFileTIFF);


}

dlg.center(); 

dlg.show();
RobC
  • 22,977
  • 20
  • 73
  • 80
  • Still haven't figured this one out. I'm thinking it's because I can't just load multiple files directly. Currently trying to figure out what Array Buffer is, hoping I'm on the right track. – Rebecca Taylor Oct 12 '17 at 19:45

1 Answers1

0

Looks like the problem is that you need to have an array to hold the files selected by the user. With that knowledge the rest of the code is reworked accordingly. Different cases were added to react to different possibilities (whether or not the array contained multiple values) and then it was just a matter of opening all the files in the array with a for loop! Hope this helps:

var dlg = new Window('dialog', 'PSD Creator', [100, 100, 500, 550] );
var selectFileTIFF = [];

dlg.pnl_browse = dlg.add('panel', [10, 10, 390, 150], 'Browse');
    dlg.pnl_browse.txt_staticPSD = dlg.pnl_browse.add('statictext' , [15, 10, 375, 30],'Select the project images folder:');
    dlg.pnl_browse.btn_browsePSD = dlg.pnl_browse.add ('button', [15, 35, 60, 60], '...');
    dlg.pnl_browse.txt_editPSD = dlg.pnl_browse.add('edittext' , [65, 35, 365, 55],'<Select the project images folder>');
    dlg.pnl_browse.txt_staticTIFF = dlg.pnl_browse.add('statictext' , [15, 70, 375, 90],'Select the folder where you TIFF images are:');
    dlg.pnl_browse.btn_browseTIFF = dlg.pnl_browse.add ('button', [15, 95, 60, 120], '...');
    dlg.pnl_browse.txt_editTIFF = dlg.pnl_browse.add('edittext' , [65, 95, 365, 120],'<Select the folder where you TIFF images are>');    

dlg.btn_ok = dlg.add ('button', [70,400,190,430], 'ok');
dlg.btn_cancel = dlg.add ('button', [210,400,320,430], 'cancel');


 dlg.pnl_browse.btn_browsePSD.onClick = function ()  {   
selectFilePSD = File.openDialog("Please select your template file.","*.psd");   
        if(selectFilePSD != null) dlg.pnl_browse.txt_editPSD.text = decodeURI(selectFilePSD.fsName); 
}


dlg.pnl_browse.btn_browseTIFF.onClick = function ()  {   
selectFileTIFF = File.openDialog("Please select your tiff images.","*.TIF; *TFF", true); 

    //selectFileTIFF is an array  thus you must loop through each selected file
    //you will need a String variable to appened the name of each file for your ScriptUI panel 
    if( selectFileTIFF.length != 0 ) {
        if( selectFileTIFF.length > 1 ) {
            dlg.pnl_browse.txt_editTIFF.text = selectFileTIFF.length + " items selected";
        } else {
            dlg.pnl_browse.txt_editTIFF.text = decodeURI( selectFileTIFF[0].fsName );
        } //end else
    } //end if
 } //end func      

dlg.btn_ok.onClick = function () {

        dlg.close()
        open (selectFilePSD);

        //must open each file is selectFileTIFF array
        for ( i = 0; i < selectFileTIFF.length; i++ ) {
        open (selectFileTIFF[i]);
        }


}

dlg.center(); 

dlg.show();
Dominic Fox
  • 118
  • 11
  • Thank you! This worked so nicely! I understand everything you did here except "var selectFileTIFF = [];" I don't understand exactly what empty square brackets do/mean here. Is it that this names selectFileTIFF as an empty array? And each item in the array is represented by a number, so selectFileTIFF[1] refers to the second item in the array? – Rebecca Taylor Oct 13 '17 at 16:50
  • No problem! And pretty much. The line `var selectFileTIFF = [];` Is saying create a brand new array for me ( `= [];` ), and then point at the array with `selectFileTIFF`. This way when you later go to store multiple files inside the variable selectFileTIFF, it is already set up for use! There is a deeper significance that has to do with static vs dynamically typed languages if you want to read more on the subject. But on the surface, you can think of that line as just preparing the variable so that it is ready for proper use. – Dominic Fox Oct 13 '17 at 16:56
  • If you look up, "how to create an array in javascript," you may find a much better explanation that what I just gave. – Dominic Fox Oct 13 '17 at 17:02