6 Replies Latest reply on Jul 26, 2013 7:14 AM by Jump_Over

    InDesign Conditional text batch export with TOC update

    wood1y

      Hello Everyone,

       

      I'm just getting into the scripting, so bear with me please.

       

      I have an indesign document with several conditional text variations and a generated Table Of Contents. I've found -hans-'s batch exporting script which works perfectly, BUT, in my document there are conditional headings too, which have their impact on the TOC of course and sadly indesign's toc update is not live. So all I need, is add a line (or 2) in the script that selects and updates the TOC for me before exporting each PDF. I've tried labeling the TOC text frame (with script label) and invoke a menu action on it, but I think I didn't get the Syntax right. I guess for someone experienced this is a really simple task.

       

      Here is -hans-'s Conditional text batch exporting script:

       

      http://forums.adobe.com/message/4764443

       

      thanks for your help!

      wood1y

        • 1. Re: InDesign Conditional text batch export with TOC update
          Jump_Over Level 5

          Hi,

           

           

          wood1y wrote:

           

          ... but I think I didn't get the Syntax right. ...

           

          The question is what is your syntax looking like?

          Do you refer to the menuAction by name or by index?

           

          If proper textFrame is selected this line should work:

          app.menuActions.item(1810).invoke();
          

           

          rgds

          Jarek

          1 person found this helpful
          • 2. Re: InDesign Conditional text batch export with TOC update
            wood1y Level 1

            Hi,

             

            Thank you for your answer. This is my syntax so far. All I did to -hans-'s script was, I tried to create a variable with a text frame that has the "TOC" label, select it with a .select action (found it on a forum) that doesn't work, and tried to invoke the update toc with app.scriptMenuActions.itemByID(71442).invoke(); which doesn't work either. So yes, as I told you, I'm a beginner.

             

             

             

            var nameOfThePDFExportPresetYouWantToUse = 'DiscManual' //please don't forget to set!

             

            var currDoc = app.activeDocument;

            var currFilePath = currDoc.filePath.absoluteURI + '/';

            var currFileName = currDoc.name.replace(/.indd/, '');

            var currConditions = currDoc.conditions;

            var myTOC = currDoc.textFrames.item("TOC")

             

             

            //set all conditions visible to false

            currConditions.everyItem().visible = false;

             

            l = currConditions.length;

             

             

            //cycle thru conditions

            while(l--){

            currCondition =  currConditions[l];

             

             

            //set actual condition visible to true

            currCondition.visible = true;

             

            currConditionName = currCondition.name

             

             

            //select TOC

            myTOC.select();

             

             

            //update TOC

            app.scriptMenuActions.itemByID(71442).invoke();

             

             

            //set pdfName

            var exportTo = File(currFilePath + currFileName + '_' + currConditionName +'.pdf');

             

            //Have a look here:

             

             

            //export PDF. to choose backgroundexport. use the second line of code

            //currDoc.exportFile(ExportFormat.PDF_TYPE, exportTo,false,  nameOfThePDFExportPresetYouWantToUse);

            currDoc.asynchronousExportFile(ExportFormat.PDF_TYPE, exportTo,false,  nameOfThePDFExportPresetYouWantToUse);

             

             

            //set actual condition visible to false

                currCondition.visible = false;

                }

            • 3. Re: InDesign Conditional text batch export with TOC update
              Jump_Over Level 5

              Hi,

               

              var myTOC = currDoc.textFrames.item("TOC");

               

              above calls a textFrame which the name is "TOC" (not a label).

              The name of textFrame is a string you can see in document levels panel.

               

              panel.jpg

               

              So edit a textFrame name there. It should help. MenuActions calling looks OK.

               

              rgds

              Jarek

              • 4. Re: InDesign Conditional text batch export with TOC update
                wood1y Level 1

                Thank you so much, it seems like it's solved.

                 

                ps.: Initially I got this (Error Number: 53762, Error String: Action is not enabled), error but in the last 10 mins it was OK without me changing anything   *shrug*

                • 5. Re: InDesign Conditional text batch export with TOC update
                  DBarned

                  Hi Jarek / anyone else who might know...

                   

                  I'm using this method but want to ask it to save into a different folder if the currConditionName is something specific.

                   

                  Is there something I can add at some point to say along the lines of:

                   

                  if currCondition.name = seperateFolder

                  var currFilePath = currDoc.filePath.absoluteURI + '/Other/';

                  var exportTo = File(currFilePath + currFileName + '_' + currConditionName +'.pdf');

                  currDoc.asynchronousExportFile(ExportFormat.PDF_TYPE, exportTo,false,  nameOfThePDFExportPresetYouWantToUse);

                  currCondition.visible = false;

                      }

                   

                   

                   

                  Not that I'm suggesting what I wrote there will work, but I'm hoping it will help show what I'm trying to do...

                   

                  Thanks in advance fo rany info!

                  • 6. Re: InDesign Conditional text batch export with TOC update
                    Jump_Over Level 5

                    Hi,

                     

                    part to modify:

                     

                    //set pdfName
                    var other = "";
                    if (currConditionName == "specificName") {
                         other = "/otherFolderName/";
                         if (!Folder(currFilePath + other).exists) 
                              Folder(currFilePath + other).create();
                         }
                    var exportTo = File(currFilePath + other + currFileName + '_' + currConditionName +'.pdf');
                    

                     

                    Jarek