5 Replies Latest reply on Sep 4, 2009 5:53 PM by HarboSenior

    Going cuckoo over nests [AS,CS3]

    HarboSenior Level 1

      As beginner continuing his intitial exploration, I have found that InDesign will quite happily allow a script to add the same nested style to a paragraph style multiple times.

       

      So if the nested style is to capitalise the first word, and the script adds it a second  time, the paragraph style will capitalise the first two words. Useful? Quite possibly, but not what I am trying to achieve.

       

      What I would like to do at the moment is have the script discover what nested styles a paragraph style has at the outset and if a particular one is missing to create it.

       

      So far I have been unable to find how to do this. Nested styles don't appear in the paragraph style's properties. So where are they hidden?

        • 1. Re: Going cuckoo over nests [AS,CS3]
          S Hopkins Adobe Community Professional

          You will find Nested Styles in the Text Suite.

          Here is some code that should get you started:

           

          tell document 1 of application "Adobe InDesign CS3"

          if paragraph style "Nested" exists then

          displaydialog "It is here"

          set styleRef to paragraph style "Nested"

          set parentStyle to name of based on of styleRef

          end if

          set styleNames to name of every paragraph style

          end tell

           

          If you think of a nested style as a paragraph style "based on" its parent style you should have no problems. The only properties of a nested style are applied character style, class, delimiter, inclusive, index, object reference, parent, properties, and repetition. All other properties (not set using a character style) revert back to the "based on" parent style. You can nest any number of character styles within a nested paragraph style.

          Hope that helps

          Shirley Hopkins

          • 2. Re: Going cuckoo over nests [AS,CS3]
            HarboSenior Level 1

            Thanks for your reply, Shirley,

             

            I think I have failed to make my problem clear enough.

             

            You appear to be talking about a paragraph style based upon another

            paragraph style, whereas I am hoping to get a script to find out

            whether or not a paragraph style has a character style nested in it.

             

            In my script I have got a list of paragraph styles, which I then

            filter down to paragraph styles containing the word "intro".

             

            In the publication I work for, all intros begin with the first word

            capped up. So I  have created a character style called "All Caps",

            which I have nested in all the intro styles I have created. No problem

            there.

             

            To ensure consistency, however, given that we handle templates created

            in all arts and parts, I want to check that all the intro paragraph

            styles have the  "All Caps" character style nested in them. If they

            don't then I intend the script to nest the character style "All Caps"

            in the offending paragraph style.

             

            I have successfully scripted setting up paragraph styles and nesting a

            character style in them.

             

            What I haven't so far  been able to do is devise a check that says

            "Yes, this paragraph style, "Bold Intro", has your character style

            "All Caps" nested in it" or "No, it doesn't".

             

            I can find that the "Bold Intro" paragraph style exists and that the

            "All Caps" paragraph style exists. What I have failed to prove is

            their conjunction.

             

            Your script fragment is helpful in looking for a particular paragraph

            style, but doesn't solve my problem.

             

            The line beginning set parentStyle appears to have something missing.

             

            It  throws the error:  -->     Adobe InDesign CS3 got an error: Can’t get

            name of based on of paragraph style id 456 of document "PushinOn.indd".

             

            But thanks again for your help.

            • 3. Re: Going cuckoo over nests [AS,CS3]
              Eric @ MCA Level 3

              Pretty sure it is the same in CS3 as CS4...

               

              What you are struggling with is getting properties of things that don't exist. First just get the list of all nested styles. If there aren't any, it's empty (length of 0) and you can throw an error. If there are some, you can then analyze the names of them all and see if the requisite name is on the list.

               

              tell application "Adobe InDesign CS4"
                   tell active document
                        set myNesteds to every nested style of paragraph style "Bold Intro"
                        if length of myNesteds > 0 then
                             set myNestedNames to name of applied character style of every nested style of paragraph style "Bold Intro"
                             if myNestedNames does not contain "All Caps" then
                                  display dialog "Alert: \"All Caps\" nested style missing from \"Bold Intro\"!"
                             else
                                  display dialog "\"Bold Intro\" is good to go."
                             end if
                        else
                             display dialog "Alert: \"All Caps\" nested style missing from \"Bold Intro\"!"
                        end if
                   end tell
              end tell

               

              EDIT:

              Actually, now I've thougth about it, you could also just get every paragraph style that has a nested style with the name "All Caps" and see if the list is longer than 0. Here's an example that can cyle through a list of styles you specify and check that each of them has the All Caps style applied.

               

              set myStyleNames to {"Bold Intro"}
              set docStyles to {}

              try
                  set docStyles to every paragraph style whose name of applied character style of every nested style contains "All Caps"
              end
              if length of docStyles > 0 then
                  set docStyleNames to name of every paragraph style whose name of applied character style of every nested style contains "All Caps"
                  repeat with thisStyleName in myStyleNames
                      if docStyleNames does not contain thisStyleName then
                          display dialog "ERROR: Style \""&thisStyleName&"\" is supposed to contain nested All Caps style, but it doesn't!"
                      end if
                  end repeat
              else
                  display dialog "ERROR: No styles with nested style All Caps found!"
              end if
              • 4. Re: Going cuckoo over nests [AS,CS3]
                sstanleyau Level 4

                >Nested styles don't appear in the paragraph style's properties.

                 

                Right -- that's because they are elements of paragraph styles, not properties.

                 

                --

                Shane Stanley <sstanley@myriad-com.com.au>

                AppleScript Pro Sessions <http://scriptingmatters.com/aspro>

                1 person found this helpful
                • 5. Re: Going cuckoo over nests [AS,CS3]
                  HarboSenior Level 1

                  Thanks to all for the help. Now I can go to bed and perhaps sleep a little!

                   

                  I had noticed in the dictionary that nested styles were an element rather than a property, which explained why I couldn't find it in a list of properties.

                   

                  I wasn' clear how to proceed, though, even when I knew that.

                   

                  ... which is why I am glad there are helpful folks like yourselves around.