8 Replies Latest reply on Dec 19, 2011 11:08 PM by amandasgarden

    Remove indent after paragraph

    amandasgarden Level 1

      I'm new to scripting and I have a problem that scripting might be able to fix.

      I have body text with indent but after headlines in the body text the indent sholud be removed. My editorial program only allowes me to use one paragraph style for the body text. When the text is placed on the page everything works fine because the editorial program fixes the text so that indent after headlines in the body text are removed.

       

      But when the pagemakers move the hadlines the indent doesn't follow. Making indents is simple by using the paragraph style and to remove the indent I now use a script.

       

      THis made me thinking.

       

      Is it possible for a script to:

      1. Identify all headlines in the body text (the paragraph style is called Mellanrubrik)

      2. Remove the indent on the body text paragraph that follows

       

      I have tried using this but I don't know what to write between the commands.

       

      if (appliedParagraphStyle=Mellanrubrik)

       

       

      app.selection[0].firstLineIndent=0

       

      Best regar

      ds

       

      Mikael Wiik, Sweden

        • 1. Re: Remove indent after paragraph
          [Jongware] Most Valuable Participant

          That's a reasonable starting point. First off, you cannot simply use the name of your style; you need to 'look it up' using "app.activeDocument.paragraphStyles.item("Mellanrubrik")". Second, if you use the Find function to locate your heads, the 'selection' will not 'hold' the next paragraph. There are several ways to increment the, uh, 'cursor' (not really) to the next paragraph, but the easiest way is to use 'nextItem' on the Found Item's paragraph object.

           

          With those adjustments, your little scriptlet works once only, and the next step would be to make it work on an entire document:

           

          1. Find all headlines.

          2. For each of the found headlines,

             a. Check if the next paragraph is your body text (I'd advise this check)

             b. If so, set its indent to '0'.

           

          (Fill in the name of your body text paragraph style below.)

           

          // 1. Find a list of all headers
          app.findTextPreferences = null;
          app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Mellanrubrik");
          list = app.activeDocument.findText(0);
          // 2. For each found item ...
          for (i=0; i<list.length; i++)
          {
          // a. Check the *next* paragraph for your body text
          if (list[i].paragraphs.nextItem(list[i].paragraphs[0]).appliedParagraphStyle == app.activeDocument.paragraphStyles.item("Body Text"))
          // b. If so, remove indent
            list[i].paragraphs.nextItem(list[i].paragraphs[0]).firstLineIndent = 0;
          }
          

           

          A disadvantage, however, would be that moving the headers around will also have left other paragraphs without an indent that should have one!

           

          You could consider to duplicate your body text style, set the indent to 0, and name it something like "Body Text After Head" -- that way you don't get a nasty "override +" -- and apply this instead of the override. When you notice someone else moved stuff around, delete this new style (!!) and replace it with your plain body text. Then re-create the style and run the script again.

          • 2. Re: Remove indent after paragraph
            amandasgarden Level 1

            Hi and thanks for the help

             

            I added my body text paragraph style and tested the script. However I got an error message, unfortunately in swedish but I will try to translate it.

             

            ---------------------------
            Adobe InDesign
            ---------------------------
            JavaScript Fel.

            Felkod: 30477
            Felsträng: Ogiltigt värde angett för egenskapen appliedParagraphStyle. String, ParagraphStyle or NothingEnum enumerator förväntades, nothing togs emot.

            Motor: main
            Fil: C:\Program\Adobe\Adobe InDesign CS5.5\Scripts\Scripts Panel\Samples\JavaScript\Kopia av Ta bort indrag.jsx
            Rad: 3
            Källa: app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Mellanrubrik");
            ---------------------------
            OK  
            ---------------------------

             

            ---------------------------
            Adobe InDesign
            ---------------------------
            JavaScript Error.

            Errorcode: 30477
            Error string: Invalid value set for appliedParagraphStyle. String, ParagraphStyle or NothingEnum enumerator was expected, nothing was recieved.

            Motor: main
            File: C:\Program\Adobe\Adobe InDesign CS5.5\Scripts\Scripts Panel\Samples\JavaScript\Kopia av Ta bort indrag.jsx
            Row: 3
            Source: app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Mellanrubrik");
            ---------------------------
            OK  
            ---------------------------

             

            Hope you can make any sense out of this.

             

            BR,

             

            Mikael Wiik

            • 3. Re: Remove indent after paragraph
              John Hawkinson Level 5

              Is your Mellanrubrik part of a style group? Try allParagraphStyles instead of paragraphStyles.

              • 4. Re: Remove indent after paragraph
                amandasgarden Level 1

                Yes, my Mellanrubrik is part of a style group. But I don’t understand, where int the can I use allParagraphStyles instead of paragraphStyles?

                 

                 

                Från: John Hawkinson forums@adobe.com

                Skickat: den 19 december 2011 14:28

                Till: Mikael Wiik

                Ämne: Remove indent after paragraph

                 

                Re: Remove indent after paragraph

                created by John Hawkinson<http://forums.adobe.com/people/John%C2%A0Hawkinson> in InDesign Scripting - View the full discussion<http://forums.adobe.com/message/4093119#4093119

                • 5. Re: Remove indent after paragraph
                  John Hawkinson Level 5

                  Edit the script. Line 3.

                  • 6. Re: Remove indent after paragraph
                    amandasgarden Level 1

                    I have tried to edit the script but noting happens. Can you point me to where in line 3 I should change anything. I have tried both in the beginning (appliedParagraphStyles to allParagraphStyles) and the end (app.activeDocument.paragraphStyles.item to app.activeDocument.allParagraphStyles.item).

                    • 7. Re: Remove indent after paragraph
                      Jump_Over Level 5

                      allParagraphStyles gives Array of objects not a collection, so item(), firstItem(), ... etc doesn't works. Use paragraphStyleGroups.item("YourGroupName") before paragraphStyles:

                      line3:

                      app.findTextPreferences.appliedParagraphStyle

                      = app.activeDocument.paragraphStyleGroups.item("YourGroupName").paragraphStyles.item("Mellanrubrik");

                      • 8. Re: Remove indent after paragraph
                        John Hawkinson Level 5

                        Whoops! Good point, thanks for the correction, Jump_Over!

                        • 9. Re: Remove indent after paragraph
                          amandasgarden Level 1

                          Thanks a lot!

                           

                          Now the script identifies my Mellanrubrik but then nothing happens.

                          I have tried changing line line 9 so it resembles line 3 since my body text is in the same style group as the header Mellanrubrik

                           

                          // 1. Find a list of all headers

                          app.findTextPreferences = null;

                          app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("A-artikel").paragraphStyles.item("Mellanrub rik");

                          list = app.activeDocument.findText(0);

                          // 2. For each found item ...

                          for (i=0; i<list.length; i++)

                          {

                          // a. Check the *next* paragraph for your body text

                          if (list[i].paragraphs.nextItem(list[i].paragraphs[0]).appliedParagraphStyle == app.activeDocument.paragraphStyleGroups.item("A-artikel").paragraphStyles.item("Brödtext" ))

                          // b. If so, remove indent

                            list[i].paragraphs.nextItem(list[i].paragraphs[0]).firstLineIndent = 0;

                          }

                          • 10. Re: Remove indent after paragraph
                            amandasgarden Level 1

                            Sorry guys

                             

                            I copy-pasted the script again and now it works. My bad.

                             

                            Now another question, is it possible to let the script search for multiple style group names at the same time?