Create batch of new documents

Home Forums InDesign User Groups Create batch of new documents

This topic contains 7 replies, has 3 voices, and was last updated by  Al Rosero 5 months ago.

  • Author
    Posts
  • #86356

    Kathy Cote
    Member

    Hi all,
    I do not know at all if what I try to find here can exist. Maybe someone of you knows. Is it possible to have a script that creates several new Indesign documents based on the information from a .txt or .csv file?

    For exemple, I could have two columns in Excel. One for the width and for the height. The script could read the informations and create new documents, save and name the files with the document size.

    I know this is a lot to ask. I wonder if it could be possible because I have more than 300 documents with different formats to create so I try to find a faster way.

    Or if you have other options to suggest, I will take it.

    thanks again for your help

  • #86365

    Ari Singer
    Member

    My posts are not going through, so I’ll try one more time:

    var file = File.openDialog("Select Your Text File", undefined, false);
    var folder = Folder.selectDialog("Select the folder where the new documents should be saved");
    file.open("r");
    var content = file.read().split("\n");
    
    for (var i = 0; i < content.length - 1; i++) {
        var curLine = content[i].split("\t");
        var h = curLine[0];
        var w = curLine[1];
        docName = h + " x " + w;
        try {
            var newDoc = app.documents.add(false);
            newDoc.documentPreferences.pageHeight = h;
            newDoc.documentPreferences.pageWidth = w;
            newDoc.save(new File(folder + "/" + docName + " .indd"));
            newDoc.close(SaveOptions.no)
            } catch(myError){}
        }
    
  • #86361

    Ari Singer
    Member

    It takes a tab-delimited text file. The first value is the height, and the second is the width. Only use numbers and don’t add measurement units (such as “mm”). The measurement units will be defined by your InDesign defaults. First the script prompts you to select the text file, and then it prompts you again to select the folder where you want the resulting files to be saved.

    –Ari

  • #87491

    Kathy Cote
    Member

    Hi Ari,
    Thank you very much for your help. I really appreciate.
    I only have a small problem with the script. I can not make it work.
    I was wondering if you could help me with that ?

    This is the JavaScript Error:
    Error Number: 25
    Error String: Expected: )

    Engine: main
    Line: 7
    Source: for (var i = 0; i < content.length – 1; i++) {

    Offending Text: ;

    Again thank you for everything ;-)

    Kathy

  • #88359

    Kathy Cote
    Member

    Hi Ari,
    I want to say thank you, it works! WOW!

    The only thing is, I can only use whole numbers. I would like to be able to use example: 45.5 X 45.5

    Is it possible ?

    Thanks ;-)

  • #88703

    Kathy Cote
    Member

    I try to modify the code but it seems to be a problem.
    I would use a .txt file with 3 columns and to use numbers with decimals.
    Ok I added the code to the 3 columns but I do not know how to modify the code to use numbers with decimals. And my other problem is that the script seems to only read the first line in the .txt file. The script does not give me an error but does not work completely.

    does anyone know?

    Example of my text in the .txt file:
    33 66 1569
    55 22 1256
    5.5 10.5 8956
    33.5 33.5 5842
    33.5 33.5 9856

    and this is my code:
    var file = File.openDialog(“Select Your Text File”, undefined, false);
    var folder = Folder.selectDialog(“Select the folder where the new documents should be saved”);
    file.open(“r”);
    var content = file.read().split(“\n”);

    for (var i = 0; i < content.length – 1; i++) {
    var curLine = content[i].split(“\t”);
    var w = curLine[0];
    var h = curLine[1];
    var c = curLine[2];

    docName = w + “X” + h + “_” + c ;
    try {
    var newDoc = app.documents.add(false);
    newDoc.documentPreferences.pageHeight = h;
    newDoc.documentPreferences.pageWidth = w;
    newDoc.save(new File(folder + “/” + docName + “.indd”));
    newDoc.close(SaveOptions.no)
    } catch(myError){}
    }

  • #88717

    Kathy Cote
    Member

    ok everyone, I’m sorry. I saw my error.
    Everything works well!

    Thanks

  • #123936

    Al Rosero
    Member

    I found this post very useful, I tried on Indesign CC 2020 and nothing happened, it asked me for the TXT document and for the Document Folder but nothing was created.

The forum ‘InDesign User Groups’ is closed to new topics and replies.