Count unused paragraph styles InDesign

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


Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

hi,

can’t test it, but I guess this line is wrong:

           set myStyle to (name of item i of myParagraphStyles) & " (" & myGroup & ")" as string

may be something like this would work:


--.....
set myStyle to (name of item i of myParagraphStyles)

--.....
           set applied paragraph style of find text preferences to myStyle of myGroup


may work, may not :confused:

Hi Hans

Thanks for trying but it still doesn’t work. I get the following error:
error “Can’t get myStyle of "body".” number -1728 from myStyle of “body”
I also tried amending the line to:

set applied paragraph style of find text preferences to myStyle of paragraph style group myGroup

and got this error:
error “Adobe InDesign CS5 got an error: Invalid value for set property ‘applied paragraph style’. Expected string, paragraph style or nothing, but received nothing.” number 30477

Ah well :frowning:
Dave

Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)