Getting base position of last element in a quarxpress page

Hi All,

I am having one task. The task is to get the base position of last element in a page of quarkxpress document. This base line position should be calculated from top trim.

Here is full description.

I have a quark document where at the end of each page there may be a picture box, line or text boxes.
If the last element in a page is a picture box, we should get the bottom position of the box from top trim, and same is for line.
If the last element in a page is a text box, we should get base position of last text line in that text box.

Can any one suggest me whether this is possible.

If possible, please suggest me the directions for this applescript.

Thanks,
Gopal

Hi krish,

I am currently reading Shirley Hopkin’s book «AppleScripting QuarkXPress» and so I took your problem as a challenge and learning experience.

Here is my sample script for you. It’s not perfect, but may already be of some interest for you. Please note, that I am currently running Leopard and QuarkXPress 7.3.1 (Demo version) on my PowerBook G4:


set report to ""

tell application "QuarkXPress Passport"
	tell document 1
		set pagenums to count of pages
		repeat with i from 1 to pagenums
			tell page i
				set report to report & ("Page No. " & i & ":" & return)
				set boxids to (uniqueID of every generic box) as list
				set boxdict to {}
				set bottomvalues to {}
				repeat with boxid in boxids
					set boxbottom to (item 1 of (bottom right of (bounds of generic box id boxid) as list)) as number
					set boxrecord to {boxid, boxbottom}
					set boxdict to boxdict & {boxrecord}
					set bottomvalues to bottomvalues & boxbottom
				end repeat
				set sortvalues to my bubblesort(bottomvalues)
				set lowestvalue to last item of sortvalues
				set lastbox to missing value
				repeat with i from 1 to length of boxdict
					set boxrecord to item i of boxdict
					if lowestvalue is equal to (item 2 of boxrecord) then
						set lastbox to generic box id (item 1 of boxrecord)
						exit repeat
					end if
				end repeat
				if lastbox is not missing value then
					set boxclass to class of lastbox
					if boxclass is in {line box, picture box} then
						set bottombox to item 1 of (bottom right of (bounds of lastbox) as list) as string
						set strclass to class of lastbox as text
						set report to report & tab & strclass & " (" & bottombox & ")" & return & return
					else if boxclass is text box then
						try
							set bl to (baseline of last line of lastbox) as string
						on error
							set bl to ""
						end try
						set topbox to item 1 of (origin of (bounds of lastbox) as list) as string
						set strclass to class of lastbox as text
						set report to report & tab & strclass & " (" & topbox & " + " & bl & ")" & return & return
					end if
				end if
			end tell
		end repeat
		return report
	end tell
end tell

on bubblesort(theList)
	-- defining an internal script makes for faster run times!
	script bs
		property alist : theList
	end script
	set theCount to length of bs's alist
	if theCount < 2 then return bs's alist
	repeat with indexA from theCount to 1 by -1
		repeat with indexB from 1 to indexA - 1
			if item indexB of bs's alist > item (indexB + 1) of bs's alist then
				set temp to item indexB of bs's alist
				set item indexB of bs's alist to item (indexB + 1) of bs's alist
				set item (indexB + 1) of bs's alist to temp
			end if
		end repeat
	end repeat
	return bs's alist
end bubblesort