• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

run a indesign script via list

Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Hello to all,

I'm not an Indesign script expert, but I need a script that adds a blank page at the bottom of multiple files.
The script must read the list of files to open and edit from an excel file placed in a folder, can anyone give me a hand on how to write it?

 

Thanks to all

Fabrizio

TOPICS
Scripting

Views

561

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

I give you some more details:
I have to start the script with an open book and the book contains several files and the structure is this:

book:
  - doc1_IT.indd
  - doc2_IT.indd
  - doc3_IT.indd
  - doc1_EN.indd
  - doc2_EN.indd
  - doc3_EN.indd
  - doc1_DE.indd
  - doc2_DE.indd
  - doc3_DE.indd

The files are divided into folders: "IT" - "EN" - "DE",
the book is outside these folders:

book folder:
  book
  "IT" folder
  "EN" folder
  "DE" folder

I place the excel file in the folder where the book is located and inside it I insert only the name "doc1", doc2 ", doc3",
the script must read the names and automatically fetch all the "IT", "EN", "DE" versions.

 

The blank page to be inserted is the "ZZ-Pag bianca" master.

 

At the following link you will find the folder just described with the files:

https://www.dropbox.com/s/yb0i0njtl7suvdy/book.zip?dl=0

 

Thanks to all

Fabrizio

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Why does it need to be from an Excel file? With an open book, all documents are available via app.activeBook.bookContents. From there you can iterate, open each book content as a doc, add your page and close. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Hi Brian, you're right, I forgot to specify that I only need this script for some files in the book.
My example is incorrect, but the structure is correct.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Again, don't think you need an Excel. Can just maintain the file list in the script, like so. 

 

var docNames = [
    "doc1_EN",
    "doc1_IT",
    "doc2_IT",
    //etc
 ];
 
 var myBook = app.activeBook;
 var myMasterName = "ZZ-Pag bianca";
 var myBc, myDoc, myMaster;
 for (var i = 0; i < docNames.length; i++) {
    myDoc = undefined;
    myBc = myBook.bookContents.itemByName(docNames[i] + ".indd");
    if (!myBc.isValid || myBc.status != BookContentStatus.NORMAL) { 
      alert(docNames[i] + " is not avaialble in your book."); 
      continue;
    }
    try { 
        myDoc = app.open(myBc.fullName);
        myMaster = myDoc.masterSpreads.itemByName(myMasterName);
        myDoc.pages.add(LocationOptions.AT_END, undefined, {appliedMaster: myMaster});
        myDoc.close(SaveOptions.YES);

    } catch(e) { 
        alert("Problem with " + docNames[i] + " - " + e); 
    }
 }
 alert("Done!");

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Thanks a lot for the script, I need to use an excel or txt file because the list of file change name everytime.
I would like to enter only the initial part of the file name (eg "doc1" - "doc2" - doc3 ") without indicating the language and in order to the script searches automatically all files starting with those names.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Here's how you would split the languages from the front part of the name. Not sure what the difference is between a txt file and maintaining the file as an array in the script. Maybe someone else will write a free data parser for you, or you can hire someone to develop exactly what you want; I'm already in "bottle of wine, at least, territory" now. Learning how to write your own data parser would be a great exercise in self-learning! 

 

var docNames = [
    "doc1",
    "doc2",
    "doc3",
    //etc
 ];

 var langs = [
   "_IT",
   "_EN",
   "_DE",
   //etc
 ];
 
 var myBook = app.activeBook;
 var myMasterName = "ZZ-Pag bianca";
 var myBc, myDoc, myMaster;
 for (var i = 0; i < docNames.length; i++) {
    for (var j = 0; j < langs.length; j++) {
      myBc = myBook.bookContents.itemByName(docNames[i] + langs[j]+ ".indd");
      if (myBc.status != BookContentStatus.NORMAL) { 
        alert(docNames[i] + langs[j] + " is not avaialble in your book. Update your book to fix it"); 
        continue;
      }
      try { 
          myDoc = app.open(myBc.fullName);
          myMaster = myDoc.masterSpreads.itemByName(myMasterName);
          myDoc.pages.add(LocationOptions.AT_END, undefined, {appliedMaster: myMaster});
          myDoc.close(SaveOptions.YES);
      } catch(e) { alert("Problem with " + docNames[i] + langs[j] + "-" + e); }
    }
    
 }
 alert("Done!");

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

Thanks again for the script.
The difference is because I don't have to edit the script every time and, in the future, I plan to make the script automatic on multiple books, but like you said, I'll find someone who will make an analyzer for me.
I tried the script but it gives me an error (attached).
If I bypass it, I insert the blank page only in the documents of the last language in the list.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Try again with my code above. Change myBook to myBc in that line. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Perfect, now it's work! Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Hi, Fabrizio:

 

You can use the Brian script with some modifications. If you export your excel to csv you obtain a txt list with the names of your documents.

 

You can acces this file with

var myFile = new File("~/Desktop/list.csv");  //Define a file object, put your own path
myFile.open("r");   //Read acces mode

 

You can read an entire line at a time with "myFile.readln()" so you obtain the excel's file name for each use.

 

Now, iterate throught the list of the txt names:

var docName; //store the name of the doc for each iteration

...

//change iteration from "for i" to "while"

while(!myFile.eof){
    docName = myFile.readln();
    //Brian's "for i" code, changing docNames[i] by docName
    }

 

You have a new name every time you run the "readln()" sentence until the End Of File (EOF).

 

At the end of the script remember close the file:

myFile.close();

 

good luck!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Hi Lluis,

Thanks so much! It all works, I just had to add an "s" in the portion you wrote me.
I ask you, is it possible to make the script open files even with only a portion of the name?
My files are encoded like this:

"A_1601a_01_IT"

"A_1601a" is the name of the file
"01" is the revision (and may change)
"IT" is the language (and can change)

I would like it to search for files based only on the portion named "A_1601a" so that if the revision changes or the language is not important.

Last thing:
I put the csv file where the book is (variable path), can the script automatically open it taking the path of the book?

Thanks so much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Hello @Lluis Scriptografus ,

 

Do you have read my message?

 

Thanks

Bye

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Hi, Fabrizio:

 

Sorry, I was on holidays!

 

I found two methods that may help you: "split" and "substr". With them you are able to extract the name you want from the long csv name. I think "split" can help you to acces both the name and the language. They are "string" methods.

 

A "book" object has a property named "filePath" (without the filename), so you can obtain the path to other files beside your book.

 

From http://jongware.mit.edu you can download help relative to this topics (thanks to Jongware, deceased last year but always remembered for his great support). Its very usefull to find properties and methods, the parents of an object, what objects can use a property, etc.

 

Good luck!

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

Hi Lluis,

Thank you so much, I look at it and hope to find what you need (hoping to be able to make it work :)).

See you soon

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines