AS InDesign CS2 paragraph style problem

I’m having a problem that sometimes my Applescript doesn’t change a paragraph style. I have the exact same line of code earlier (almost immediately before the line causing problems) and it works fine. Also, sometimes it works and sometimes it doesn’t. What I’m doing is I select a paragraph (3 in this case) and change the paragraph style.


set applied paragraph style of paragraph 3 of text frame ("Info"&(i)) to "Call Agent MLS"

So I’m baffled. Any thoughts anyone?

Thanks.

Hi PB

Post your full script!

OK, but it’s long. Again, thanks for any help.
Here’s the complete script


-- STORES PATHS

set housePath to "Images_1:Real estate houses (Coldwell):"
-- the path to the folder with the current home images

set mugPath to "Images_1:Realestate MUGS:Coldwell Banker:"
-- the path to the folder with the realtor mugs

set hammerPath to "Hammer:Real Estate Scripts:COLDWELL AYS:"
set oldhammerPath to "Hammer:AppleScripts:Coldwell:"

-- the path to the template, database, etc.


-- STORES DATA ABOUT THE CURRENT AD PACKAGE

set runningDate to text returned of (display dialog "What is the publication date of this ad?" default answer "x-x-2007") as string
-- stores the publication date, which the database uses to find the current records

set pagetoBuild to text returned of (display dialog "What page do you want to build?" default answer "") as string
-- stores the page number

set formatOptions to {"Full Page", "Half Vert"} as list

set pageFormat to (choose from list formatOptions with prompt "What format do you want?") as string
-- stores the desired format, which will determine the template file to use
-- If there are more than 3 format options you must use a list instead of buttons

if pageFormat = "Full Page" then
	set itemLimit to 25
	-- sets the limit two items higher in case of an unusual layout
	-- the extra two items are placed on the side of the page
else if pageFormat = "Half Vert" then
	set itemLimit to 10
end if
-- stores the number of items a chosen format can handle

-- OPENS THE DATABASE AND COUNTS THE CURRENT RECORDS 


tell application "FileMaker Pro"
	activate
	open file (hammerPath & "Coldwell home database.fp7")
	-- opens the database file
	-- change file path accordingly
	tell database "Coldwell home database"
		try
			show (every record whose cellValue of field "Running in issue" = runningDate and cellValue of field "Page" = pagetoBuild)
			--create new request
			-- initiates a find
		on error
			display dialog "The database encountered an error. " & ¬
				"Please check the date in the database and make sure the publication data you enter matches exactly." buttons "Cancel"
			return
		end try
		set databaseCount to (count of (every record whose cellValue of field "Running in issue" = runningDate and cellValue of field "Page" = pagetoBuild))
		-- count of found, not all
	end tell
end tell

-- FIGURES OUT HOW MANY HOUSE LISTINGS THERE ARE 

tell application "Finder"
	activate
	if button returned of (display dialog "The database found " & databaseCount & " records for the current issue. " & ¬
		"If this is correct, click OK to continue. If not, click Cancel and check the database.") is "Cancel" then
		return
		-- cancels script if requested .
	end if
	if databaseCount ≠ itemLimit then
		if button returned of (display dialog "The format you've chosen can accomodate more or less than the number of found records. " & ¬
			"Press OK to continue or Cancel to cancel the script.") is "Cancel" then
			return
			-- The script will try to keep going if requested, even if the numbers don't match.
		end if
	end if
	if databaseCount > itemLimit then
		set recordsToPlace to itemLimit
	else
		set recordsToPlace to databaseCount
	end if
	-- stores the number of records to try and pull in without getting an error
end tell


-- OPENS THE INDESIGN DOC

tell application "Adobe InDesign CS2"
	activate
	open alias (hammerPath & "Coldwell AYS REM " & pageFormat & ".indd")
	-- opens the appropriate InDesign template
end tell

-- GATHERS ALL THE INFO FROM THE DATABASE
tell application "FileMaker Pro"
	tell database "Coldwell home database.fp7"
		show (every record whose cellValue of field "Running in issue" = runningDate and cellValue of field "Page" = pagetoBuild)
	end tell
	-- same as above
	
	sort by field "position" in order ascending
	-- sorts the FOUND records
end tell

repeat with i from 1 to recordsToPlace
	-- tries to place either the number of available positions or the number of found listings, whichever is smaller
	tell application "FileMaker Pro"
		--tell document 1
		tell record i
			set houseList to (get cells 1 thru 15)
			-- grabs all the cells of a record
			-- according to filemaker documentation, this is faster than getting and setting each individual cell
			set mlsNumber to item 1 of houseList
			set hotlineNumber to item 2 of houseList
			set openInfo to item 3 of houseList
			set houseAddress to item 4 of houseList as string
			set leadText to item 7 of houseList
			set houseDescription to item 8 of houseList
			set virtualTour to item 9 of houseList
			set housePrice to item 10 of houseList
			set realtorName to item 11 of houseList
			set realtorMug to item 12 of houseList
			set bannerText to item 14 of houseList
			set flagMessage to item 15 of houseList
			set leadVar to (count of characters of leadText)
			set priceVar to (count of characters of housePrice)
			if virtualTour = "Yes" then
				set tourText to "See Virtual Tour. "
			else
				set tourText to ""
			end if
		end tell
		--end tell
	end tell
	
	-- DUMPS THE INFO INTO INDESIGN
	
	tell application "Adobe InDesign CS2"
		activate
		tell document 1
			tell page 1
				try
					tell rectangle ("House" & (i))
						place (housePath & "Cold." & mlsNumber & ".dcs")
						fit given content to frame
						-- fits the image without white
					end tell
				end try
				
				-- does nothing if mug or mug box isn't found
				
				try
					set contents of text frame ("Address" & (i)) to houseAddress --as string
				end try
								
				if hotlineNumber = "" then
					--try
					set contents of text frame ("Info" & (i)) to openInfo & return & leadText & " - " & houseDescription & " " & tourText & return & "MLS#" & mlsNumber & tab & "$" & housePrice & return & realtorName
					search text frame ("Info" & (i)) for "*" replacing with tab
					set applied paragraph style of paragraph 1 of text frame ("Info" & (i)) to "Open time"
					set applied paragraph style of paragraph 2 of text frame ("Info" & (i)) to "Description"
					delay 1
					try
						set applied paragraph style of paragraph 3 of text frame ("Info" & (i)) to "Call Agent MLS"
					on error
						display dialog "Check format for box " & ("Info" & (i))
					end try
					tell text frame ("Info" & (i))
						tell paragraph 2
							set applied character style of characters 1 thru (leadVar + 2) to "Lead"
							--set applied character style of characters ((count of characters) - (priceVar + 1)) thru (count of characters) to "Price"
						end tell
					end tell
					try
						search text frame ("Info" & (i)) for "*" replacing with tab
					on error
						display dialog "* not changed"
					end try
					--set applied paragraph style of paragraph 3 of text frame ("Info" & (i)) to "Realtor"
					if word 1 of realtorName = "CALL" then
						try
							set justification of paragraph 3 of text frame ("Info" & (i)) to center align
						end try
					end if
					--end try
				else
					try
						set contents of text frame ("Info" & (i)) to openInfo & return & leadText & " - " & houseDescription & " " & tourText & return & "MLS#" & mlsNumber & " #" & hotlineNumber & tab & "$" & housePrice & return & realtorName
						search text frame ("Info" & (i)) for "*" replacing with tab
						set applied paragraph style of paragraph 1 of text frame ("Info" & (i)) to "Open time"
						set applied paragraph style of paragraph 2 of text frame ("Info" & (i)) to "Description"
						delay 1
						try
							set applied paragraph style of paragraph 3 of text frame ("Info" & (i)) to "Call Agent MLS"
						on error
							display dialog "Check format for box " & ("Info" & (i))
						end try
						tell text frame ("Info" & (i))
							tell paragraph 2
								set applied character style of characters 1 thru (leadVar + 2) to "Lead"
								--set applied character style of characters ((count of characters) - (priceVar + 1)) thru (count of characters) to "Price"
							end tell
						end tell
						try
							search text frame ("Info" & (i)) for "*" replacing with tab
						on error
							display dialog "* not changed"
						end try
						--set applied paragraph style of paragraph 3 of text frame ("Info" & (i)) to "Realtor"
						if word 1 of realtorName = "CALL" then
							try
								set justification of paragraph 3 of text frame ("Info" & (i)) to center align
							end try
						end if
					on error
						display dialog "oops"
					end try
				end if
			end tell
		end tell
		
	end tell
end repeat


Hi pb

It is a little difficult for me to check this without a similar setup as yourself,can’t understand when you say:

it sometimes works!
Some values most be changing from time to time for it to work on and off.
However at a glance the only thing i could see that might cause a problem is the words “paragraph style” is missing.
Add it on the end like this…

set applied paragraph style of paragraph 3 of text frame ("Info" & (i)) to paragraph style "Call Agent MLS"

However if it works on the few lines of code before this line then i’m not sure!

It’s a shot in the dark i know! Sorry

The thing that gets me is that the problematic line of code works most of the time. I tried adding “paragraph style” before the name of the paragraph style but it doesn’t work when run. I’ve tried a delay 1 to slow it down to see if that would help but it doesn’t. I’m stumped.

Well I figured it out. If I have too many characters/words in the text box and the paragraph I want to change is not visible (part of overset), it won’t change the paragraph style. Weird. I wouldn’t think changing paragraph styles would matter if it was overset or not.

Thanks everybody.

you could check for the overset text then reduce the font size to until there is no overset text anymore then apply your paragraph styles

I don’t have your InDesign template or database to check this out but if the problem is due to overflow you can address your statement to the story instead of the text frame since the story contains the entire text while the text frame only contains the text that is visible. So the following should fix your problem:

set applied paragraph style of paragraph 3 of parent story of text frame ("Info" & (i)) to "Call Agent MLS"