InDesign CS4: Bottommost object in stacking order

I am trying to determine if an object in InDesign CS4 is at the bottom of the stacking order on its layer. I haven’t seen any reference to an object’s stacking order in the Dictionary. The one thing that may help me is the fact that “Send to Back” is grayed out when the object is bottommost. I have yet to try System Events to “try” this, and then undo if it succeeds. Likewise if it errors I would have my answer. However, I don’t think system events “error” if the menu item isn’t accessible, not to mention there is probably a better way”I don’t trust an undo?

Anybody want to take a stab at this one? I don’t blame you if you don’t.

The stacking order is the index property of the page item, with 1 being the top most item. So you could do this:

tell application "Adobe InDesign CS4"
	tell document 1		
		set x to count of page items
		set selection to page item x of page 1
	end tell
end tell

or this:

tell application "Adobe InDesign CS4"
	tell document 1
		set selection to last page item of page 1
	end tell
end tell

To change the stacking order you would use:

		bring to front page item 3 
		send backward page item 1
		send to back page item 2
		bring forward page item 3

Jerome,
You don’t know how glad I am that you replied to my post.

This is what I needed. However I needed to test for this on a layer, but that part was simple.

Thank you very much.

Not that I need this functionality below.
But maybe you can point me in the right direction for future reference. What if I was trying to determine if a selected object was the bottommost object. My script is not working, and I tried other things to no avail.

tell application "Adobe InDesign CS4"
tell application "Adobe InDesign CS4"
	activate
	tell document 1
		set sel to selection
		set x to page item of sel
		set theLayer to layer 1
		set x to count of page items of theLayer
		if x is last page item of theLayer then
			--do something here
			display dialog "wow, this is the bottom object of the stacking order of layer 1"
		end if
	end tell
end tell
end tell

OK some errors in your code explained.

First ID returns a list of items for the selection even if there is only one item so that needs to be converted to a single item for testing.

then you are converting x to the count of the page items, but in your if statement you are trying to compare the objects.

The below code should work.

tell application "Adobe InDesign CS4"
	--activate
	tell document 1
		set sel to selection
		set sel to item 1 of sel
		set theLayer to layer 1
		if sel is last page item of theLayer then
			--do something here
			display dialog "wow, this is the bottom object of the stacking order of layer 1"
		end if
	end tell
end tell

It works perfectly! Gosh, I could have sworn that I tried that exact code at one point. but I guess not.
Thank you once again.

No problem, seems to come fairly easy to me. Wish I could make a living at it.

Jerome:

You should put out some feelers. I do make a living at it (and have for 13+ years).

Good luck to you!
Jim
BLUEFROG

Blue, I have been doing it for over 13 years as well. I wouldn’t know where to start actually finding paying work. I have had one company in Australia contact me for a job, but other than passing interest no one I have talked to is interested or seems to see the value in actually paying for it.