Setting bleed in QuarkXPress

I am working on a script to set the bleed automatically to elements that fall within a specific threshold of the page edge in a quark 6 document…what I have now works, but is still in the making…and I have 2 queries:

  1. the script now sets bleed for any object that falls within .05" of the right page edge, and this works unconditionally, but what if the page item in question is on a page that is part of a spread (ie. picture box whose right bounds sits up against the next page in a spread)

  2. the script will currently set the box to the values that i want by resizing it, which means that any image inside of the box will get shifted to the left and up

Any help or suggestions on these will be greatly appreciated, as I said…this script is still in the works, it’s close, but still needs a little fine tuning

tell application “QuarkXPress”
tell document 1
set view scale to fit page in window
set horizontal measure to inches
set vertical measure to inches
set right_threshold to 0.05
set left_threshold to 0.05
set top_threshold to 0.05
set bottom_threshold to 0.05
set page_width to page width as real
set page_height to page height as real
set pic_boxes to count of picture boxes

	repeat with i from 1 to pic_boxes
		
		set left_edge to left of bounds of picture box i --get the left edge
		set left_edge to my get_number(left_edge) --convert it to a number
		if left_edge < left_threshold then -- if the picture is near the edge
			my bleed_left(i)
		end if
		
		set right_edge to right of bounds of picture box i
		set right_edge to my get_number(right_edge) --convert it to a number
		set new_right_edge to page_width + 0.25
		if right_edge is equal to page width or right_edge is equal to 0 or right_edge + 0.05 �
			is greater than or equal to page width as real or right_edge + 0.05 is equal to 0 then
			set right of bounds of picture box i to new_right_edge
		end if
		
		set top_edge to top of bounds of picture box i --get the top edge
		set top_edge to my get_number(top_edge) --convert it to a number
		if top_edge < top_threshold then -- if the picture is near the edge
			my bleed_top(i)
		end if
		
		set bottom_edge to bottom of bounds of picture box i
		set bottom_edge to my get_number(bottom_edge) --convert it to a number
		set new_bottom_edge to page_height + 0.25
		if bottom_edge is equal to page_height or bottom_edge + 0.05 is greater than or equal to page height as real then
			set bottom of bounds of picture box i to new_bottom_edge
		end if
		
	end repeat
end tell

end tell

on bleed_left(i) --stretch the picture to the left
set new_left_edge to -0.25
set q_edge_value to make_q_number(new_left_edge) --format it properly
tell application “QuarkXPress”
tell document 1
set left of bounds of picture box i to q_edge_value
end tell
end tell
end bleed_left

on bleed_top(i) --stretch the picture to the left
set new_top_edge to -0.25
set q_edge_value to make_q_number(new_top_edge) --format it properly
tell application “QuarkXPress”
tell document 1
set top of bounds of picture box i to q_edge_value
end tell
end tell
end bleed_top

on get_number(q_value) --converts a quark measurement(“1.34"”) to a real (1.34)
set q_value to q_value as string
set n_chars to the number of characters in q_value
set value to (characters 1 through (n_chars - 1) of q_value) as string
set value to value as real
end get_number

on make_q_number(value) --converts a number(3.14) to a Quark value(“3.14"”)
set value to value as string
set value to value & “”"
end make_q_number

Could you look at the object reference to see what page a picture’s on? Is your doc layout standard? If so, odd pages are on the right, even left.

You need to think in terms of spreads, not pages.

Also, for the second part, you can look at some of the example scripts that come with QXP6 for pointers.

Here’s what I think you are looking for in a single code segment (I also make some of the parameters into properties, and cleaned up the coersion coding).

property bleed_value : 0.25
property right_threshold : 0.05
property left_threshold : 0.05
property top_threshold : 0.05
property bottom_threshold : 0.05

tell application "QuarkXPress 6.1"
	activate
	tell document 1
		-- Save the current view settings
		set oldView to view scale
		set oldHoriz to horizontal measure
		set oldVert to vertical measure
		set oldSpread to item spread coords
		
		set view scale to fit page in window
		set horizontal measure to inches
		set vertical measure to inches
		set item spread coords to true -- The real magic in making the spreads work
		
		set page_width to page width as real
		set page_height to page height as real
		set new_edge to 0 - bleed_value
		
		-- Process each spread individually
		set spread_list to every spread as list
		repeat with x in spread_list
			-- Get a list of picture boxes on the current spread
			set pic_boxes to every picture box in every page of x as list
			-- Set the spread width based on the current spread
			set spread_width to (count of pages of x) * page_width
			
			-- Process each picture box on the spread
			repeat with i in pic_boxes
				-- Process the left edge
				set edge to (left of bounds of i as inch units) as real
				if edge < left_threshold then
					tell i
						-- We need to adjust the offset of the image to make it appear in the same relative place
						set theOffset to (get offset of image 1)
						set theOffset to coerce (theOffset as measurements point) to list
						set yoffset to (item 1 of theOffset as inch units) as real
						set xoffset to (item 2 of theOffset as inch units) as real
						
						set l to (left of bounds) as real
						set diff to new_edge - l
						
						set item 1 of theOffset to (yoffset)
						set item 2 of theOffset to (xoffset - diff)
						set theOffset to (theOffset as inches point)
						set offset of image 1 to theOffset
						
						-- Now we can set the bounds						
						set left of bounds to new_edge as inch units
					end tell
				end if
				
				-- Process the right edge
				set right_edge to (right of bounds of i as inch units) as real
				set new_right_edge to spread_width + bleed_value
				if (right_edge is equal to spread_width) or ¬
					(right_edge is equal to 0) or ¬
					(right_edge + right_threshold is greater than or equal to spread_width as real) or ¬
					(right_edge + right_threshold is equal to 0) then
					-- No need to adjust the offset, just fix the right edge
					set right of bounds of i to new_right_edge
				end if
				
				-- Process the top edge
				set top_edge to (top of bounds of i as inch units) as real
				if top_edge < top_threshold then
					tell i
						-- We need to adjust the offset of the image to make it appear in the same relative place
						set theOffset to (get offset of image 1)
						set theOffset to coerce (theOffset as measurements point) to list
						set yoffset to (item 1 of theOffset as inch units) as real
						set xoffset to (item 2 of theOffset as inch units) as real
						
						set t to (top of bounds) as real
						set diff to new_edge - t
						
						set item 1 of theOffset to (yoffset - diff)
						set item 2 of theOffset to (xoffset)
						set theOffset to (theOffset as inches point)
						set offset of image 1 to theOffset
						
						-- Now we can set the bounds						
						set top of bounds to new_edge as inch units
					end tell
				end if
				
				-- Process the bottom edge
				set bottom_edge to (bottom of bounds of i as inch units) as real
				set new_bottom_edge to page_height + bleed_value
				if (bottom_edge is equal to page_height) or ¬
					(bottom_edge + bottom_threshold is greater than or equal to page_height as real) then
					-- No need to adjust the offset, just fix the bottom edge
					set bottom of bounds of i to new_bottom_edge
				end if
				
			end repeat
		end repeat
		
		-- Set the view and scale options back to the original settings
		set view scale to oldView
		set horizontal measure to oldHoriz
		set vertical measure to oldVert
		set item spread coords to oldSpread
	end tell
end tell