populate file list to use later

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

lukasz

populate file list to use later

Post by lukasz »

I'm trying to populate a list of files, so I can select "template files" and it populates to an array (I think?) to be used later. also needs a continue button, so that way it knows when to exit the loop. basically I just need it to loop and add files to the array until they say "I am done adding files"

I very new to arrays, so this is a bit new to me. This is probably way off:

Code: Select allfor (var t = 0) {
    var templateFiles = new Array();
    var templateFiles[t] = File.openDialog("Select a template to use");
    // decide if continue
      var res = confirm("done selecting templates?");
   try{
      if( res ) t++;
   }catch(e){}
}

// here it needs to loop through files just letting me know it loaded them
(var f = 0; f >= t; f++)
   alert (templateFiles[t]);
}




Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

populate file list to use later

Post by Mike Hale »

A couple of suggestions.

1. Use a while loop and define templateFiles outside the loop
Code: Select allvar res = false;
var templateFiles = new Array();
while(!res){
    var f = File.openDialog("Select a template to use");
    if(f != null) templateFiles.push(f);
    // decide if continue
      res = confirm("done selecting templates?");
}or to avoid the multi continue prompts
Code: Select allvar f = 'flag';
var templateFiles = new Array();
while(f != null){
    f = File.openDialog("Select a template to use");
    if(f != null) templateFiles.push(f);
    // continue until user cancels
}
2. Another way to avoid the multi prompts is to use the multiSelect argument in openDialog to allow the users to select as many files as needed.
Code: Select allvar templateFiles = File.openDialog("Select a template to use",undefined,true);// returns either an array of selected file(s) or null if the user canceled.
lukasz

populate file list to use later

Post by lukasz »

that is perfect, exactly what I was trying to do, works a lot easier than what I had imagined.

how would I go about cycling through the array?
I want to open the files, but it returns an error, assuming its trying to use the entire array at once, instead of individual elements? Not really sure what is happening.

Code: Select allvar templateFiles = File.openDialog("Select a template to use",undefined,true);// returns either an array of selected file(s) or null if the user canceled.
app.open(templateFiles);
Mike Hale

populate file list to use later

Post by Mike Hale »

Yes, what you have is telling Photoshop to open an array. It needs a file object.

If you want to open all the files at once you cloud do something like this.
Code: Select allfor(var f = 0;f < templateFiles.length;f++ ){
    app.open( templateFiles[f] );
    // or do your processing here and save/close the document before the next is opened
}