Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

applescript - ID - CS3 or CS4 - create array containing front/back order of objects?

Guest
Jun 08, 2010 Jun 08, 2010

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)

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jun 08, 2010 Jun 08, 2010

When you ask for the page items on a page/spread/document, the list comes back in stacking order already.

Translate
Advocate ,
Jun 08, 2010 Jun 08, 2010

When you ask for the page items on a page/spread/document, the list comes back in stacking order already.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 08, 2010 Jun 08, 2010

Fantastic - thanks! Worked like a charm.

I appreciate your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2010 Aug 17, 2010

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

The rectangle gets returned first in the list, instead of third.
This post:
describes a way around the problem using javascript to get an array of page items. The array's index is ordered by stacking order. But I'm not sure how to achieve this in applescript.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2010 Aug 17, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2010 Aug 17, 2010

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...).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2010 Aug 17, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 18, 2010 Aug 18, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2010 Aug 18, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 18, 2010 Aug 18, 2010

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".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2010 Aug 18, 2010

Thanks, those are great ideas. I'll try them out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2010 Aug 18, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 18, 2010 Aug 18, 2010

Have you turned off Enable Redraw, either via the menu on the Scripts panel or via script preferences?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2010 Aug 18, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 18, 2010 Aug 18, 2010
LATEST

> 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines