I’m trying to select page items that are within a set geometric location on the page. This way I can create several grouping on one page. Below is what I have so far; it creates a rectangle for the items to group to, sends it to back, (tries) to locate all page items within those bounds, and (tries) to group them with the new rectangle.
tell application "Adobe InDesign CS2"
activate
set theFile to active document
tell theFile
tell page 1
---rectangles for grouping
set slideLeftAOne to (make rectangle with properties {geometric bounds:{1.7344, 0.5, 5.984, 7.9063}, stroke color:"None", fill color:"None", label:"slideLeftAOne"}) send to back
set allItemsLeftAOne to every page item in {geometric bounds:{1.7344, 0.5, 5.984, 7.9063}}
set groupAllItemsLeftOne to make group with data {group items:allItemsLeftAOne}
end tell
end tell
end tell
Unless you really need it you don’t actually have to have to make the rectangle. You could make it more flexible by letting the select a rectangle and using the bounds of that as the reference for the group. This should help you:
tell application "Adobe InDesign CS2"
activate
tell document 1
--set TheBounds to geometric bounds of selection
set TheBounds to {20.791666666667, 17.479166666667, 41.10119047619, 35.458333333333}
set TheObjects to every page item whose item 1 of geometric bounds ≥ item 1 of TheBounds and item 2 of geometric bounds ≥ item 2 of TheBounds and item 3 of geometric bounds ≤ item 3 of TheBounds and item 4 of geometric bounds ≤ item 4 of TheBounds
set NewGroup to make group with data {group items:TheObjects}
end tell
end tell
One thing to mention is in the end this script will create more than one group of items per page. I’m creating the rectangle first to have a nice bounding area that can be used to align the groups. I’ve had problems grouping items before. I’m wondering if it’s a problem of referring to the group record as a property of the page or page items.
The reason for the invalid parameter is that you are working on a multi page document and not “telling” the page that you are working on. I wrote it real quick in a 1 page document and didn’t need to address a page number for the script to work.
tell application "Adobe InDesign CS2"
activate
tell document 1
set TheBounds to geometric bounds of selection
tell page 3
set TheObjects to every page item whose item 1 of geometric bounds ≥ item 1 of TheBounds and item 2 of geometric bounds ≥ item 2 of TheBounds and item 3 of geometric bounds ≤ item 3 of TheBounds and item 4 of geometric bounds ≤ item 4 of TheBounds
set NewGroup to make group with data {group items:TheObjects}
end tell
end tell
end tell
Not knowing exactly how you are using the script I’m not sure how to suggest getting the page of the current object. If you are automatically processing an entire document and grouping everything in the upper right quadrant of each page (for example) you could just repeat through the pages. If this is something that an indivudual is running on a specific page then you need to find the parent page of that you are working on, something similar to this:
tell application "Adobe InDesign CS2"
activate
tell document 1
set TheBounds to geometric bounds of selection
set mypage to parent of item 1 of selection
tell mypage
set TheObjects to every page item whose item 1 of geometric bounds ≥ item 1 of TheBounds and item 2 of geometric bounds ≥ item 2 of TheBounds and item 3 of geometric bounds ≤ item 3 of TheBounds and item 4 of geometric bounds ≤ item 4 of TheBounds
set NewGroup to make group with data {group items:TheObjects}
end tell
end tell
end tell