12 Replies Latest reply on Jul 10, 2014 7:50 PM by Colin Flashman

    Script to autoflow multiple text files?

    AnneMarie Concepcion Adobe Community Professional

      A publisher I'm working with is being slowed down by a necessary change to their workflow. Maybe there's a script around to help? I've looked but can't find any, so I'm posting here.

       

      Old workflow: Designers would autoflow a single, large Word doc that contained all front matter (sometimes >10 diff. sections) and chapters and endnotes into a book template.

       

      New workflow: The Word doc is now broken up into 30-40 InCopy files, still destined for a single InDesign layout doc. (The InCopy files were created from a tagged Word doc by a different system, so they're all new to the InDesign user.)

       

      Is there a script that, after the designers load a Place cursor with the 30-40 files (in the correct order), will allow them to single-click on page 1, and InDesign will place one after the other of the files, autoflowing as necessary? They still need them to be placed as individual InCopy files (so concatenating first wouldn't help). I don't think there would ever be a case of 2 stories being on the same page.

       

      thanks,

      AM

        • 1. Re: Script to autoflow multiple text files?
          TᴀW Adobe Community Professional & MVP

          Does the script have to use the place gun? And does it have to happen

          after they've clicked the place gun?

           

          The alternatives would be:

           

          (a) they load the place gun, and then, to run the script, double-click

          on it in the scripts panel instead of clicking the place gun. (The place

          gun does seem to have scriptable events, but I could not find any

          corresponding to placing the first item in it).

           

          (b) skip the place gun altogether, and simply run a script which lets

          them select multiple files on their harddrive, and then places them

          automatically one after the other. That would be simplest, perhaps.

           

          Ariel

          • 2. Re: Script to autoflow multiple text files?
            AnneMarie Concepcion Adobe Community Professional

            No, they don't have to use the Place gun. It's kind of mindless, what they have to do in InDesign, there's no need for a human to be in charge at this point. All text flows into the same master page's active text area.  The only thing they do after placing a file via Shift-click (to autoflow) is to add on a new page at the end of the previous's autoflow in which to start the next one.

             

            So if a script knew to do that (to autoflow and add pages when necessary) then sure, they could use either method.

             

            AM

            • 3. Re: Script to autoflow multiple text files?
              TᴀW Adobe Community Professional & MVP

              What version of InDesign are they using?

               

              When you say "master page's active text area", do you mean the area

              inside the regular page margins?

              • 4. Re: Script to autoflow multiple text files?
                AnneMarie Concepcion Adobe Community Professional

                they're using CS6, and yes, I mean the area inside the page margins.

                • 5. Re: Re: Script to autoflow multiple text files?
                  TᴀW Adobe Community Professional & MVP

                  Hi AnneMarie,

                   

                  This script will allow you to select a bunch of files, and will attempt to place them, one by one, into your InDesign document. It will auto-flow them as needed (although watch out for permanent overset problems -- because the script does not test for that).

                   

                  I've tested this with a bunch of assets, but not with InCopy files because I don't have any. If they're placeable like Word documents, the script should run fine.

                   

                  Let us know if it all works properly for you.

                   

                  // BS"D
                  // Multi-file auto-place
                  // An InDesign Script by Ariel, (c) Id-Extras.com, 2014
                  // This script will allow the user to select a bunch of placeable files (Word docs, etc.)
                  // It will then attempt to place and auto-flow all the selected files.
                  // The script will start from page 1 of the active document
                  // and keep adding pages as needed.
                  // It will add text frames as needed, within the margins of the page.
                  // IMPORTANT: There is no error-checking for perpetual overflow!!!
                  // So, if something you're trying to place cannot fit within the margins,
                  // The script will continue adding pages to InDesign until it crashes.
                  // To quit the script, press ESC.
                  var myDoc = app.activeDocument,
                   myFiles = File.openDialog("Select files to place...", undefined, true),
                   i,
                   currentPage = myDoc.pages[0],
                   prevFrame,
                   myFrame;
                    
                  for (i = 0; i < myFiles.length; i++){
                   myFrame = addFrame(currentPage);
                   myFile = myFiles[i];
                   try{
                    myFrame.place(myFile, false);
                   }
                   catch(e){
                    alert("Unable to place file: "+myFile, "Multi-file auto-place");
                    continue;
                   }
                   while (myFrame.overflows){
                    currentPage = addPageAfter(currentPage);
                    prevFrame = myFrame;
                    myFrame = addFrame(currentPage);
                    prevFrame.nextTextFrame = myFrame;
                   }
                   currentPage = addPageAfter(currentPage);
                  }
                  function addFrame(aPage){
                   var pageMargins = aPage.marginPreferences,
                    aFrame = aPage.textFrames.add(),
                    areFacing = app.activeDocument.documentPreferences.facingPages,
                    myTop = aPage.bounds[0]+pageMargins.top,
                    myBottom = aPage.bounds[2]-pageMargins.bottom,
                    myLeft = aPage.bounds[1]+pageMargins.left,
                    myRight = aPage.bounds[3]-pageMargins.right;
                   //When document.documentPreferences.facingPages == true,
                   //"left" means inside; "right" means outside.
                   if (areFacing && aPage.side == PageSideOptions.LEFT_HAND){
                     myLeft = aPage.bounds[1]+pageMargins.right;
                     myRight = aPage.bounds[3]-pageMargins.left;
                   }
                   aFrame.geometricBounds = [myTop, myLeft, myBottom, myRight];
                   return aFrame;
                  }
                   
                  function addPageAfter(aPage){
                   return myDoc.pages.add(LocationOptions.AFTER, aPage);
                  }
                  
                  • 6. Re: Script to autoflow multiple text files?
                    AnneMarie Concepcion Adobe Community Professional

                    thanks! How do I extract just the script text? I keep getting the line numbers.

                    • 8. Re: Script to autoflow multiple text files?
                      AnneMarie Concepcion Adobe Community Professional

                      Nevermind, duh! I just pasted into Text Wrangler which understood the text numbers.

                       

                      The script appears to work great with InCopy files!

                       

                      I'll put my client in touch with you so they can contract with you, if necessary, to tweak this for their needs (add error-checking for ex).

                       

                      AM

                      • 9. Re: Script to autoflow multiple text files?
                        TᴀW Adobe Community Professional & MVP

                        Yes -- there's a lot of room for improvement: error checking, setting

                        layers, objects styles, etc.

                         

                        This script is just a "proof of concept" -- although it should work

                        nicely in a limited set of cases.

                         

                        Ariel

                        • 10. Re: Script to autoflow multiple text files?
                          HarveyLiu Level 1

                          a lot of problem in there

                          • 11. Re: Script to autoflow multiple text files?
                            HarveyLiu Level 1

                            What I need is reliable became first.

                            • 12. Re: Script to autoflow multiple text files?
                              Colin Flashman Adobe Community Professional

                              I'm probably too late to the party here, but would this script from Peter Kahrel be of any use?

                               

                              http://www.kahrel.plus.com/indesign/place_documents.html

                               

                              Colin