7 Replies Latest reply on Sep 12, 2014 8:14 AM by ryan_pu

    Sellect TOC with script

    ryan_pu Level 1

      I've been trying not to asked a question every step of the way but, I'm no good at this.

       

      I am now trying to select the TOC with script so I can use other scripts (idea being able to do a set of actions to 3 different items with 1 click). I think I am looking for something like this:

       

      app.select( app.activeDocument.pageItems.item("preface") );

       

      From what I read, that stopped being good in CS5 and now I need to loop through the whole thing to find something that I name in the script lable area. I can't find any examples of a current good example of this. Any help would make me smile.

       

      Here is what I got so far:

       

      /*    REFRESH TOC WITH NEW CHAPTER STUFF    */

      /*app.select( app.activeDocument.pageItems.item("preface") );  */
      app.scriptMenuActions.itemByID(71442).invoke(); //Update TOC

       

      /*    UPDATE STYLING OF TOC AFTER REFRESH    */
      app.findChangeGrepOptions.includeLockedLayersForFind = true;
      app.findChangeGrepOptions.includeLockedStoriesForFind = true;
      app.findChangeGrepOptions.includeHiddenLayers = true;
      app.findChangeGrepOptions.includeMasterPages = true;
      app.findChangeGrepOptions.includeFootnotes = true;

      app.findGrepPreferences = app.changeGrepPreferences = null;

      app.findGrepPreferences.findWhat = "\\^n\\^yPage";
      app.changeGrepPreferences.changeTo  = "\\n~yPage";
      app.activeDocument.changeGrep();

       

       

      Thanks again.

        • 1. Re: Sellect TOC with script
          TᴀW Adobe Community Professional & MVP

          I'm not clear what you're trying to do. Are you trying to figure out

          with a script which of all the stories in an InDesign doc is the TOC story?

           

          If so, note that a Story has a storyType object, so:

           

          if (myStory.storyType == storyTypes.TOC_STORY) { etc.

           

          should get you on your way...

          • 2. Re: Sellect TOC with script
            ryan_pu Level 1

            the way the editors need this thing set up calls for a TOC that requires roman numerals, numbers and appendices  (A1, A2) so I built 3 TOC. In script panel I named them because I read to do that some where. Now I want to be able with one click to select all 3 or 1 at a time and apply the update script and the redo formatting script that I had already got made.

             

            I can't figure out how to call the TOC. I shouldn't need to parse the whole document since I will have the names available but I don't know. Everything in this program seems unnecessarily difficult. of course it doesn't help I first saw the program a couple days ago.

            • 3. Re: Sellect TOC with script
              [Jongware] Most Valuable Participant

              Worth adding that the current line

               

              app.activeDocument.changeGrep();

               

              will find & change in the entire document, which (likely) will not make you smile

               

              Instead, call "changeGrep" on the story you located when using Ariel's method:

               

              myStory.changeGrep();

              • 4. Re: Sellect TOC with script
                ryan_pu Level 1

                I used ^N^T before the word as a flag type thing so it would only change where I wanted but it is good to know of a more local option.

                 

                Happen to know how to select the toc by name or any way I didn't think of?

                • 5. Re: Sellect TOC with script
                  TᴀW Adobe Community Professional & MVP

                  Do you mean you added a script label somewhere?

                   

                  Well, you can't add a script label to a story. You probably added it (if

                  that's what you did) to the first textFrame containing your TOC. And

                  (admittedly it's a little confusing but you'll doubtless get the hang of

                  it with a little persistance, as we all did many moons ago) even if the

                  TOC takes up only one textFrame, a textFrame is not the same object as

                  the story.  The textFrame is what the story is in. To get the Story

                  object to which the textFrame belongs, you've got

                   

                  myStory = myTextFrame.parentStory;

                   

                  So, assuming you did label 3 text frames in your document with a script

                  label, I don't think there's any way you can access them directly by

                  scriptLabel without looping through all textFrames in the document.

                   

                  However, if you happened to name them in the Layers panel instead, and

                  if you called one of them Bob, you could then do this:

                   

                  myDoc.textFrames.itemByName("Bob")

                   

                  Once you've got your frame, you've got your Story, as explained above.

                  • 6. Re: Sellect TOC with script
                    ryan_pu Level 1

                    I thought I updated this last night but I guess it failed. Here is a screenshot of what i have selected and the script label that was given to it.

                    sample.jpg

                     

                    I'll try your suggestions in the mean time. Thanks

                    • 7. Re: Sellect TOC with script
                      ryan_pu Level 1

                      Here's what I got to make it work. Can't paste in the browser for some reason so here is a screen.

                       

                      sample2.jpg

                       

                      I agree with using change grep on the story instead of the whole doc but honestly, I'm still wrapping my brain around that concept. This works for now but I will probably clean it up later. I also labled the frame in the layers instead of the script lable as suggested.

                       

                      Also on an embarrassing note, I spent way to long to realize I needed to declare myDoc and that it wasn't a predefined variable.