QuarkXPress 6.5 ignoring layer property

This script is designed to create a rectangle on every page in a document, in a layer called “sealer” and filled with an 80% tint of a colour called “sealer”. The rectangle will bleed off 3mm on each edge.

This script works perfectly on single pages. However, when it is run on a document with two or more pages next to each other, even if the spreads are not set up as “facing pages”, it only puts alternate tint panels on the “sealer” layer, the other goes on the default layer. This despite the rectangle properties specifying the same layer throughout.

-- Script to add a sealer to every page in the QuarkXPress document.
-- Creates a new colour called "sealer" with 12% of each of CMYK (same values as V1_Varnish)
-- Creates a new layer called "sealer" to enable sealers to be switched on and off
-- Draws a box 6mm bigger than page, filled with "sealer" colour.

-- Kalessin, 6 July 2006
-- Revision: 4 August 2006
--		Added error checking to detect existing colours and layers

tell application "QuarkXPress Passport"
	activate
	if not (front document exists) then return -- make sure a document is open
	tell document 1
		set useLayer to "No"
		set useColour to "No"
		set sName to "sealer"
		if (layer sName exists) then
			display dialog "A layer called \"sealer\" already exists. Do you want to use this layer?" buttons {"Yes", "No"} default button 1
			if the button returned of the result is "Yes" then
				set useLayer to "Yes"
			else
				return
			end if
		end if
		if (color spec sName exists) then
			display dialog "A colour called \"sealer\" already exists. Do you want to use this colour?" buttons {"Yes", "No"} default button 1
			if the button returned of the result is "Yes" then
				set useColour to "Yes"
			else
				return
			end if
		end if
		set thePageWidth to the (width of the bounds of page 1 as real)
		set thePageHeight to the (height of the bounds of page 1 as real)
		set theOldPageOrSpreadRulerChoice to the item spread coords -- keep this value to reset afterwards
		set the item spread coords to false -- page co-ordinates, not spread
		set theOldRulerOrigin to the page rule origin -- keep this value to reset afterwards
		set the page rule origin to {0, 0} -- reset default ruler position
		if (useLayer is "No") then
			make new layer at beginning with properties {name:"sealer"} -- new layer goes above other layers
		end if
		if (useColour is "No") then
			make new color spec at beginning with properties {name:"sealer", CMYK color value:{7864, 7864, 7864, 7864}} -- CMYK values of 12% each
		end if
		set allpages to count of every page
		repeat with i from 1 to count of pages
			try
				tell page i
					make new generic box at beginning with properties ¬
						{bounds:{-3, -3, thePageHeight + 3, thePageWidth + 3}, color:"sealer", layername:"sealer", shade:"80", runaround:none runaround, background trap:overprint} -- includes 3mm bleed all around the page
				end tell
			on error
				-- display dialog "An error occurred." buttons {"OK"} default button 1
			end try
		end repeat
		set the page rule origin to theOldRulerOrigin -- revert to original settings
		set the item spread coords to theOldPageOrSpreadRulerChoice -- revert to original settings
	end tell
end tell

Hopefully, the fix is something simple and obvious which will leave me looking a little red-faced. However, I’m prepared for the worst… :wink: All assistance gratefully received.

Kalessin, this works just fine for me. Not sure what the problem is have you tried to cover the spread using only 1 box don’t know if that is an option.

tell application "QuarkXPress"
	activate
	if not (front document exists) then return -- make sure a document is open
	tell document 1
		set useLayer to "No"
		set useColour to "No"
		set sName to "sealer"
		if (layer sName exists) then
			display dialog "A layer called \"sealer\" already exists. Do you want to use this layer?" buttons {"Yes", "No"} default button 1
			if the button returned of the result is "Yes" then
				set useLayer to "Yes"
			else
				return
			end if
		end if
		if (color spec sName exists) then
			display dialog "A colour called \"sealer\" already exists. Do you want to use this colour?" buttons {"Yes", "No"} default button 1
			if the button returned of the result is "Yes" then
				set useColour to "Yes"
			else
				return
			end if
		end if
		set thePageWidth to the (width of the bounds of page 1 as real)
		set thePageHeight to the (height of the bounds of page 1 as real)
		set theOldPageOrSpreadRulerChoice to the item spread coords -- keep this value to reset afterwards
		set the item spread coords to false -- page co-ordinates, not spread
		set theOldRulerOrigin to the page rule origin -- keep this value to reset afterwards
		set the page rule origin to {0, 0} -- reset default ruler position
		if (useLayer is "No") then
			make new layer at beginning with properties {name:"sealer"} -- new layer goes above other layers
		end if
		if (useColour is "No") then
			make new color spec at beginning with properties {name:"sealer", CMYK color value:{7864, 7864, 7864, 7864}} -- CMYK values of 12% each
		end if
		repeat with i from 1 to count of spreads
			set SpreadPages to count of pages of spread i
			set theSpreadWidth to thePageWidth * SpreadPages
			try
				tell page 1 of spread i
					make new generic box at beginning with properties ¬
						{bounds:{-3, -3, thePageHeight + 3, theSpreadWidth + 3}, color:"sealer", shade:"80", runaround:none runaround, background trap:overprint} -- includes 3mm bleed all around the page
				end tell
			on error
				-- display dialog "An error occurred." buttons {"OK"} default button 1
			end try
		end repeat
		set the page rule origin to theOldRulerOrigin -- revert to original settings
		set the item spread coords to theOldPageOrSpreadRulerChoice -- revert to original settings
	end tell
end tell

Thank you very much for looking into this. Your suggestion has helped me, although it hasn’t completely fixed the problem. I did want to create a single tint panel across spreads but hadn’t looked at doing that yet. To enable you to replicate the problem I’m having (if you’re still interested), I’ve tested both scripts with a variety of QuarkXPress documents and this is what I found:

90 blank single pages: both scripts work.
45 blank spreads: both scripts work.
90 single pages with dummy content: both scripts work.
45 spreads with dummy content: spread script works, single page script fails as described previously.
Customer-supplied 96pp file (spreads plus 2 single pages): both scripts fail.

This leaves me thinking that the problem may be related to the particular settings of some QuarkXPress files. In addition, I noticed that in the customer’s supplied file, not only do some of the tint panels appear on the Default layer rather than the sealer layer, but they also appear beneath some existing items on the pages.

Many thanks for your help so far. Hopefully there’s enough information here to fix this annoying bug!