Javascript: How to loop through files -


i making illustrator cs6 javascript following:

  1. open folder of illustrator files
  2. open each file in folder (these files called source files)
  3. select contents of source file
  4. copy contents of source file
  5. create new target file paste these contents target file new layer
  6. ensure new layer has same name old source file

my script works except, doesn't loop through files in source folder correctly. instead, runs fine on first source file. endlessly pastes second source file in destination document (i.e. doesn't move onto of other source file). endlessly pastes , have force quit!

how can loop through folders , move onto next file.

here code:

// javascript document //set vairaibles var destdoc, sourcedoc, sourcefolder, newlayer;  // select source folder. sourcefolder = folder.selectdialog('select folder illustrator files want mere one', '~'); destdoc = app.documents.add();  // if valid folder selected if (sourcefolder != null) {     files = new array();      // files matching pattern     files = sourcefolder.getfiles();      if (files.length > 0) {         // destination save files         (i = 0; < files.length; i++) {             sourcedoc = app.open(files[i]); // returns document object             var mylayers = sourcedoc.layers; // select layers in active document             //go through layers of source document , copy artwork             (i = 0; < mylayers.length; i++) {                 mylayers[i].hasselectedartwork = true;             };              with(sourcedoc) {                 var count = pageitems.length;                 (var = 0; < count; i++) {                     pageitems[i].selected = true;                 }                 redraw();                 copy();                 (var = 0; < count; i++) {                     pageitems[i].selected = false;                 }               }              //create new title variable has title of source document             var title = sourcedoc.name;             var title = title.substring(0, title.length - 4); //(remove extension name)             //close source document             sourcedoc.close(saveoptions.donotsavechanges);              //open destination document , create new layer in named after title variation             newlayer = destdoc.layers.add();             newlayer.name = title;              //paste new layer             newlayer = app.paste();          }     }     else {         alert('no matching files found');     } } 

ps. wasn't sure if should post in code review or graphic design, think stack overflow best place post general question javascript looping, hope right place.

it appears using "i" variable in each of loops, giving range of unexpected values in other loops use same variable. try using separate variable each loop. e.g. j=0, k=0, l=0, etc.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -