[AS][IDCS2] Search style applied to text and change text-frame fill.

Trying to repeat through every spread og a file to check for applied paragraph styles use in text frames. If applied style is the same as the set variable, then set the text frame fill to “none”. But no matter what the variation of the wording or approach it won’t work.


tell application "Adobe InDesign CS2"
	activate
	tell active document
		set TwoPageTitle to paragraph style "2-Page Title"
		set OnePageTitle to paragraph style "1-Page Title"
		set minBoxFill to paragraph style "Minibox Title"
		repeat with p from 1 to count every spread
			tell spread p
				repeat with f from 1 to (count of text frames)
					tell text frame f
						if text frame does not contain text then
							delete text frame
						else
						repeat with p from 1 to (count of paragraphs)
							tell paragraph p
								if applied paragraph style is minBoxFill then
									set fill color of text frame to "[None]"
else, etc. etc. etc.

Hi McPants,

try something like this

tell application "Adobe InDesign CS2"
	set TwoPageTitle to "2-Page Title"
	set OnePageTitle to "1-Page Title"
	set minBoxFill to "Minibox Title"
	set framesToDelete to {}
	tell active document
		repeat with oneFrame in (get text frames of spreads)
			if contents of oneFrame is "" then set end of framesToDelete to contents of oneFrame
			repeat with oneParagraph in paragraphs of oneFrame
				if name of applied paragraph style of oneParagraph is TwoPageTitle then
					set fill color of contents of oneFrame to swatch "None"
				end if
			end repeat
		end repeat
		delete framesToDelete -- I don't know if this works, if not, use a repeat block
	end tell
end tell

“In valid parameter” This is what I kept getting before as well. It’s as if the “[None]” swatch isn’t a true swatch, but I can’t see any situation where the fill could be treated as a boolean to say “no fill.” Or I’m missing something.

I’ll keep hacking away at it, thank you for your help and any other ideas that may pop into your head. This forum has been a life-saver.

Stacy

OK, the problem that you are running into is that you need to address the paragraph of the contents of the text frame or story rather than the paragraph of the text frame. You can do this either by stepping through the text frames or the stories. I find it more efficient and less troublesome to step through stories since they span linked text frames (its the same story so for each linked text frame attached to the story there is one less item to repeat through) and include overset. Stepping through the paragraphs of a text frame will ignore the overset text. I have changed some of the code around a bit:

tell application "Adobe InDesign CS2"
	activate
	set theSwatch to object reference of swatch "None" of document 1
	set TheStyle to object reference of paragraph style "2-Page Title" of document 1
	tell document 1
		try --trapped in a try statement in case there are no empty boxes. You could do an if, but this should work just as well.
			delete (every text frame whose contents is "")
		end try
		set TheStories to every story --text frame
		repeat with i from 1 to count of TheStories
			set z to (object reference of every paragraph of contents of item i of TheStories whose applied paragraph style is TheStyle)
			repeat with aPar in z
				set fill color of aPar to theSwatch
			end repeat
		end repeat
	end tell
end tell

Note that I first set TheSwatch and TheStyle to the object reference of the item. This may not be necessary but I find it more efficient. I also deleted all empty text frames first which will speed things up a bit. Hope this helps.

An easier way to handle this would be to change the paragraph style.