
Copy link to clipboard
Copied
Hi all,
I'm looking for ideas of how to do this: create a layer for each object in the document, then move each object onto it's own layer — and preserve front/back arrangment. In other words, 10 objects = 10 layers, without changing stacking order.
So far I've got it creating unique layers and moving objects onto each. . .but i'm looking for the most efficient way to have it handle the original stacking order.
I suppose i can start learning how to build an array, then re-order it by index (which i understand indicates front/back), and then create layers following that order? If that's the best way, I'd LOVE some direction on how to code that. Or, if there a more elegant solution?
Thanks for any help!
CS3 is ideal but can use CS4 if necessary (or CS5 if there's some killer function in there)
1 Correct answer
When you ask for the page items on a page/spread/document, the list comes back in stacking order already.
Copy link to clipboard
Copied
When you ask for the page items on a page/spread/document, the list comes back in stacking order already.

Copy link to clipboard
Copied
Fantastic - thanks! Worked like a charm.
I appreciate your help!
Copy link to clipboard
Copied
Not if they are different types of object. (At least not in CS5)
I tried making 4 text frames and one rectangle with the rectangle in the middle (position 3 in stacking order). Then ran:
tell application "Adobe InDesign CS5"
set myDocument to active document
tell myDocument
set myPage1 to page 1
set myItems1 to page items of myPage1
end tell
Copy link to clipboard
Copied
Yes, this has changed in CS5, along with the broadening of the definition of what a page item is (now including images).
You can get the index of the items and sort them that way, but it would probably be quicker to do something like this:
tell application "Adobe InDesign CS5"
tell document 1
every item of all page items of page 1 whose class is in {rectangle, oval, polygon, graphic line, text frame}
end tell
end tell
That should match what was returned in versions before CS5, skipping things like images.
Copy link to clipboard
Copied
Thanks. That works for my test file, but not the real-world file. Your language returns too many items, since some of my page items are tables that include photos placed into rectangles inside of cells. I need to get at only the top level page items on the page, not the rectangles within the table. Maybe I should use your language then filter out items whose parent is not a spread? Only I'm not sure if that is the most efficient way (or exactly how to do it...).
Copy link to clipboard
Copied
This worked:
every item of all page items of myTempPage whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread)
But the whole script runs much more slowly than the previous version of it that I used in CS2. Are there script performance issues to be aware of in CS5 (or CS4 or CS3) that were not an issue for CS2?
Copy link to clipboard
Copied
I don't know that it's a performance issue per se, but rather a slowdown because it's having to filter more items.
What does your script do with the list of items? There might be a better approach.
Copy link to clipboard
Copied
It's a vertical imposition script. Items from the top half of each page are moved to a different page (using a temp page as a staging area), then pages are reshuffled. Here is the script:
tell application "Adobe InDesign CS5"
set myDocument to active document
save myDocument
set fp to file path of myDocument
set DocName to name of myDocument
if DocName ends with ".indd" then
set DocName to characters 1 thru -6 of DocName as string
end if
set myFileName to fp & DocName & "-imposed.indd" as string
tell myDocument
repeat with i from 2 to 7
set myPage1 to page i
set myPage2 to page (16 - i)
set myTempPage to page 15
set myItems1 to (every item of all page items of myPage1 whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread))
set myItems2 to (every item of all page items of myPage2 whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread))
repeat with myPageItemCounter from (count myItems1) to 1 by -1
set myitem to item myPageItemCounter of myItems1
set locked of myitem to false
set mybounds to geometric bounds of myitem
if item 3 of mybounds < 52.5 then
tell myitem to move to myTempPage
tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
end if
end repeat
repeat with myPageItemCounter from (count myItems2) to 1 by -1
set myitem to item myPageItemCounter of myItems2
set locked of myitem to false
set mybounds to geometric bounds of myitem
if item 3 of geometric bounds of myitem < 52.5 then
tell myitem to move to myPage1
tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
end if
end repeat
set myTempItems to (every item of all page items of myTempPage whose (class is in {rectangle, oval, polygon, graphic line, text frame}) and (parent's class is spread))
repeat with myPageItemCounter from (count myTempItems) to 1 by -1
set myitem to item myPageItemCounter of myTempItems
set mybounds to geometric bounds of myitem
tell myitem to move to myPage2
tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
end repeat
end repeat
delete page 15
move last page to after page 1
move last page to after page 3
move last page to after page 5
move last page to after page 7
move last page to after page 9
move last page to after page 11
save myDocument to myFileName
end tell
end tell
Copy link to clipboard
Copied
If all the items are on a single layer, you could group them, move them, then ungroup them -- layer order would be conserved for you.
You can also extend your whose clauses to include the test for position: " and item 3 of its geometric bounds < 52.5".
Copy link to clipboard
Copied
Thanks, those are great ideas. I'll try them out.
Copy link to clipboard
Copied
I extended the whose clause and gave my mac a restart and that helped. But it is still about 3-4 times slower than essentially the same script in CS2. It seems like the moves are going really slowly. Is there a difference between cs2 and cs5 in how the redrawing is handled by default when moving items?
Copy link to clipboard
Copied
Have you turned off Enable Redraw, either via the menu on the Scripts panel or via script preferences?
Copy link to clipboard
Copied
Mystery solved. Now its down to about half the time as in cs2.
Was redraw off by default for scripts run from the scripts panel in cs2?
Copy link to clipboard
Copied
> Was redraw off by default for scripts run from the scripts panel in cs2?
I can't recall -- but it's a sticky setting and a script might have set it.

