0

I'm writing an indesign script that will open a dialog, allow the user to select multiple text files, and then it loops over each file, replaces text in the document with the info in the file, saves out an InDesign file, then moves to the next text file and repeats (so we end up with an equal number of indd docs as text files the user selected)

I have everything mostly working, the one issue I have, is i have a loop going over the text files, doing the work to replace, then saving - But when i select TWO or more text files, my loop dies the second i do the save on the first file, so it never does more than 1.

Im guessing the save is killing the script execution somehow... there are no errors. Does anyone know a way around this?

aescript
  • 1,775
  • 4
  • 20
  • 30

1 Answers1

0

Oops - solved, i was just being a javascript noob. Im using document.saveACopy - which seems to work, but my initial problem was my counter in the file loop was used in another function as well - so when it came back to loop again (where 2 is the max) it was at 5. Used to python local scopes i guess.

Solved!

aescript
  • 1,775
  • 4
  • 20
  • 30
  • 1
    JS has local scopes too but the scope of some var depends on how you declared it. Plus I think it's always a bad practice to nest loops. – Loic Sep 11 '17 at 07:52
  • its not that they were nested - i think the issue stemmed from the mix of defined and undefined variables in loops that got me... difference between (i = 0; - < whatever; i++) and (int i = 0;....) from some copy/pasted code – aescript Sep 14 '17 at 22:17
  • I got that. I was just stating that avoiding nested loops is a good way not to have this kind of troubles ;) Personnally, i use and call secondary functions when I would need nested loops. – Loic Sep 15 '17 at 08:51
  • Yeah I gotcha I'm just not actually using any nested loops hah. What I meant was I had 2 short loops executing one after another and they had the same increment variable so the second loop was starting too high, Instead of at 0. But I'll keep the thought to avoid nesting loops when I Js in mind! Thanks for your comments! – aescript Sep 16 '17 at 13:54