InDesign, put each page item on its own layer in stacking order?

Anybody know the answer to this problem:
In InDesign, is there a way to put each page item on its own layer in stacking order?

The problem is this:
Each page item has its own uniek ID but only within its own class.
This means there can be two page items with ID 1 (for example a rectangle and a polygon).

Strange is that applescript sees every object as a page item:
˜count page items’.
But when you give the assignment to select the front page item:
˜set selection to front page item’ it selects the top item of the class ˜rectangle’.
Not the polygon that is on top of the page. Try it.
So how do I overcome this problem?

There must be a way to keep the stacking order of every element when placing each item on its own layer?

So this is what i have and doesn’t work:

Thanx in advance.

Hi. The problem is that your method targets the front item, rather than the indexed list, and, when you move the layers to a new position, you are reordering their indexes. If you use your code with items on multiple pages, you will end up having deleted at least one object.

tell application "Adobe InDesign CS3"'s document 1 to repeat with this in (get page items)
	duplicate this to make new layer at back
end repeat

*edited for clarity

Thank U for your (quick) reply,

sorry but this doesn’t work for me.
Indesign always makes a layer at the front i read somewhere and its true:
“duplicate page item 1 to make new layer at back” still makes a layer at the front.

and your script changes the order of the items. I’ve tested it.
You bypass the problem i gave about class.

“set selection to back page item” doesn’t work for me when you draw a rectangle with a polygon/line on top of it.
It selects the polygon/line which is at the front and not the back.

Any other Idees?

p.s. You are talking about an index list? How do i get this or approach this? Maybe the solution is in this?

I can’t tell if that’s a good or bad thing from your perspective, as I was trying to bypass a problem. You actually deleted items, where I only duplicated them, so”for testing”you may want to toggle the original layer off to see the changes”that or replace duplicate in my example with move.

Is this the code you ran? I never advised that; it’s just a rewording of your original method, which can’t work.

If ID will only make things for you at the front, then that is probably a bug relative to your version or installed setup. Explicitly using get to obtain the items, as I have done, should realize all items into a list”regardless of class”in their stacked order; i.e., by index. If you want the opposite order for your layers, you can flip it; e.g. (get page items)'s reverse.

Thank you for your response,

First I want to say that i don’t mean to be smart or rude or something like that. I’m way too glad you’re trying to help!
But i still have the problem. You’re code doesn’t work for me. Not in CS6 and not in CC. So i don’t think it is a bug or wrong setup. (Maybe it does in CS3, u use it in your code?)

‘get to obtain the items, as I have done, should realize all items into a list”regardless of class”in their stacked order’,
this is in my opinion not true. I’ve drawn a rectangle, on top of it a graphic line and there on top of it another rectangle.
Three elements, with the line in the middle.

When I use you’re piece of code: ‘get page items’, it returns a list with the line as last item, so it is not in stackin order.
I see in your code you use CS3, maybe there it does, i can’t check this.

Any idees what i’m doing wrong or so?

ps, found this: https://forums.adobe.com/thread/288877
so it looks like its not ‘easily’ possible.

Problem Solved!

thanx to another forum, i came up with this applescript solution (for anyone who cares):

Greetz, Eric

Hmm. I’m glad you found something to work for your situation, but this fundamental behavior change is very user unfriendly, and it strikes me as a bug that should’ve been reported long ago.

A poster”Harbs”from your link indicates that the duplication/grouping method is unneccesary. His advice is 1) get page items, 2) get their indexes, 3) compare. Out of curiosity, what result is returned from this in CS6 or CC?


tell application "Adobe InDesign CS3" 
	tell (make document)
		repeat with object in {rectangle, oval, rectangle, graphic line}
			make object
		end repeat
		get page items's {class, index}
	end tell
end tell

Hi,

this is the result when i run your script in CC:

{{oval, rectangle, rectangle, graphic line}, {3, 2, 4, 1}}

Tomorrow I’ll run it in CS6 (at my work) and post the result.

Kind regards, Eric

Hi, Eric. That result is fine. It just looks like the page item collection in later versions is strangely sorted. I think that this will also work, and it should significantly reduce the number of events:


tell application "Adobe InDesign CS3"'s document 1
	set {theIndex, theID, totality} to page items's {index, id, count}
	repeat with num from totality to 1 by -1
		repeat with val from 1 to totality
			if theIndex's item val = num then exit repeat
		end repeat
		move page item id (theID's item val) to make layer with properties {name:"Layer " & num}
	end repeat
	delete layer -1 --source
end tell

Marc Anthony,

Works great! This was what I was looking for. (The result in CS6 is the same by the way)
I understand the working of your script, but I couldn’t have made it so simple.

Thank you.

Kind Regards