InDesign: Troube With Frame Sorting Script

I’m having trouble with the script below. It almost works. Here’s what it’s supposed to do:

For a given InDesign CS3 document:

  1. Get a list of every graphic frame on a given page.
  2. Filter out any frames that are not of a specified size.
  3. Sort the the filtered list so that frame are listed from page top to bottom, left to right (essentially sorting first by the X coordinate and then by the Y coordinate).

The result is close but a few frames are out of place. It’s a pretty simple script and I can’t figure out where I went wrong. Can anyone spot my mistake?


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

This is complicated enough that I don’t believe it can easily be resolved without access to your test file. It’s not a glaring error, but I suspect that the rounding may be at issue - e.g., if the following is received as a result of the dimension check, your handler will round to 3, but not necessarily the expected match:

set x to 10 ^ 3
(((0.8755 * x) + 0.5) div 1) / x

This may or may not be the problem; as I said, it’s hard to test just by reading. You may want to see all the bounds after they’ve been processed through GetSize - you could test it by temporarily adding in a dialog to display the result.

Thanks for your reply. I figured out my problem, when copying the tempList to ther finalList. I was not accounting for the fact that the templist was a list of lists, not a simple list of items. What I needed to do was copy it one item at a time to the finalList. So this:

   set tempList to my bubbleSort2(tempList)
   copy tempList to end of finalList

became ths:

   set tempList to my bubbleSort2(tempList)
   repeat with z from 1 to count of items in tempList
          copy item z of tempList to end of finalList
   end repeat

and that fixed the problem. My only problem now is that the script slows down considerably as it iterated through pages in the doc. I’ve added a repeat loop to have it sort boxes on all pages in the doc one page at a time. It starts off moving pretty quickly but slows to a crawl after the first cople paes. Not sure why as it should be repeating the exact same actions on each page. I would think that each page should take the same amount of processing time (provided of course that the pages contain the same number of frames, which they do).