InDesign compare stacking order of page items

Is there a way to compare the stacking order of two different page items?

For example, I want to know if (A) text frame that matches some specific geometric bounds is above or beneath (B) a rectangle that contains a PDF graphic.

I cannot seem to figure out how to derive at this.

Any help would be greatly appreciated.

Thanks,

-Jeff

In case anybody wants to know the answer to this:

( all page items ) was the key. Getting a list of all page items and then checking each item for some condition can get you the number of the item. Then you can do the same thing for another item in the same list that matches some other condition. You can then compare the numbers and determine, which item is above/below the other.


tell application id "com.adobe.InDesign"
tell active document
set allPageItems to all page items
		repeat with i from 1 to count of items of allPageItems
			set myBounds to geometric bounds of item i of allPageItems as string
			if myBounds contains "234.614 pt347.717 pt357 pt609 pt" then
				set myAddressFrameNumber to i
				display dialog "The address frame was item " & myAddressFrameNumber & " of the stacking order"
			end if
			try
				set myItem to class of item i of allPageItems as string
				if myItem is "PDF" then
					set myPDFNumber to i
					display dialog "The PDF was item " & myPDFNumber & " of the stacking order" as string
				end if
			end try
		end repeat
end tell
end tell

1 Like

Interesting question. I don’t have an immediate answer.

If you don’t get an answer here, may I suggest to post your question to the InDesign forum here:

The reality is the majority of InDesign scripters are using JavaScript so they’re not on MacScripter. You may get an answer in JS, which you can then easily convert to AppleScript,

If I have understood the question correctly, I think the answer may be a bit simpler. If you select the first page item you are interested in and run this then select the other item and run it again you will have the index of each — the lower number is higher in the stack.

tell application id "com.adobe.InDesign"
	activate
	tell active document
		set in1 to (index of item 1 of selection)
		display dialog (in1 as string) with title "Index in Stack"
	end tell
end tell