2 Replies Latest reply on May 7, 2011 6:07 PM by Divster

    Count unused paragraph styles

    Divster

      I would like to audit my students' InDesign documents to find out if they have been tidy with their stylesheets. I have a script that partially works (I think it will work in CS4 as well, if you change CS5 to CS4).

       

      The bit that won't work is trying to record the styles that are within groups. I have commented in the script to show the error section. I get the error:

       

      "Invalid value for set property 'applied paragraph style'. Expected string, paragraph style or nothing, but receved \"body text (body)\"."number 30477

       

      I was trying to put the style name and the group in, because that is the way it works if you do it manually, ie body text (body). But it doesn't work.

       

      Any help would be appreciated.

      property myTypeReport : "" -- makes it available everywhere
      set myTypeReport to "" -- prevents the report becoming accumulative when running repeatedly
      tell application "Adobe InDesign CS5"
         set myDocument to document 1
         set unusedStyles to ""
         set myFoundItems to ""
        
         set myDescription to "Unused paragraph styles"
         set myParagraphStyleGroups to every paragraph style group of myDocument
         set myParagraphStyles to every paragraph style of myDocument
        
         repeat with i from 3 to (count of myParagraphStyles)
             set myStyle to name of item i of myParagraphStyles
             set find text preferences to nothing
             set change text preferences to nothing
             set applied paragraph style of find text preferences to myStyle
             tell myDocument
                 set myFoundItems to find text
                 if (count myFoundItems) = 0 then set unusedStyles to (unusedStyles + 1)
             end tell
         end repeat
        
         -- this is the error section
         repeat with x from 1 to count of myParagraphStyleGroups
             set myGroup to name of item x of myParagraphStyleGroups
             set myParagraphStyles to all paragraph styles of paragraph style group myGroup of myDocument
             repeat with i from 1 to (count of myParagraphStyles)
                 set myStyle to (name of item i of myParagraphStyles) & " (" & myGroup & ")" as string
                 --return myStyle
                 set find text preferences to nothing
                 set change text preferences to nothing
                 set applied paragraph style of find text preferences to myStyle
                 tell myDocument
                     set myFoundItems to find text
                     if (count myFoundItems) = 0 then set unusedStyles to (unusedStyles + 1)
                 end tell
             end repeat
         end repeat
         -- end error section
        
         set myReport to "(" & unusedStyles & ")" & "\t\t" & myDescription
         if (count unusedStyles) > 0 then set myTypeReport to myTypeReport & myReport & return
         return myTypeReport
      end tell

        • 1. Re: Count unused paragraph styles
          John Hawkinson Level 5

          Can you make better use of all paragraph styles of document instead of paragraph styles of document, which should access styles independent of groups? You would have to give over using the name as a reference (probably wise in any case) and use the style itself (in your Find/Change).

          • 2. Re: Count unused paragraph styles
            Divster Level 1

            Hi John

             

            Thanks for your advice - using the id meant that I didn't need to specify whether or not the paragraph style was in a group. I've posted the amended script below, which works a treat.

            Thanks again.

             

             

            property myTypeReport : "" -- makes it available everywhere

            set myTypeReport to "" -- prevents the report becoming accumulative when running repeatedly

            tell application "Adobe InDesign CS5"

            set myDocument to document 1

            set unusedStyles to ""

            set myFoundItems to ""

             

            set myDescription to "Unused paragraph styles"

            set myParagraphStyles to all paragraph styles of myDocument

             

            repeat with i from 3 to (count of myParagraphStyles)

            set myStyle to item i of myParagraphStyles

            set find text preferences to nothing

            set change text preferences to nothing

            set applied paragraph style of find text preferences to myStyle

            tell myDocument

            set myFoundItems to find text

            if (count myFoundItems) = 0 then set unusedStyles to (unusedStyles + 1)

            end tell

            end repeat

            set myReport to "(" & unusedStyles & ")" & "\t\t" & myDescription

            if (count unusedStyles) > 0 then set myTypeReport to myTypeReport & myReport & return

            return myTypeReport

            end tell

             

            Message was edited by: Divster