It seems the “make group” fails every time. I’ve re-written the line over and over with no sucess. Please let me know if anyone knows the answer.
tell application “InDesign CS”
set {a, b, c, d} to bounds of page 1 of document 1
set theSel to selection
if (count of theSel) > 1 then
–here is the broken line
make group at parent of item 1 of theSel with data theSel
–end broken line
set {w, x, y, z} to geometric bounds of result
undo document 1 – undo the grouping
else
set {w, x, y, z} to geometric bounds of item 1 of theSel
end if
move selection by {(d / 2 - (x + z) / 2), (c / 2 - (w + y) / 2)}
end tell
Thanks,
Frustrated Coder
Can you post the result of:
set theSel to selection
also substitute
get parent of item 1 of theSel
for
make group at parent of item 1 of theSel with data theSel
and see what that returns.
-N
Thanks for your response. I appreciate it. Here is what is returned in the Event Log when the script runs:
Code:
tell application “InDesign CS”
set theSel to selection
get parent of item 1 of theSel
end tell
Event Log:
tell application “InDesign CS”
get selection
{rectangle id 140 of page id 131 of spread id 126 of document “Untitled-2”, rectangle id 139 of page id 131 of spread id 126 of document “Untitled-2”}
get parent of rectangle id 140 of page id 131 of spread id 126 of document “Untitled-2”
page id 131 of spread id 126 of document “Untitled-2”
end tell
I don’t know if that helps you. I just see alot of id numbers which seem useless. I still get the error from Indesign “can’t make group”.
Let me know if you have more suggestions.
Model: G5
Browser: Firefox 1.0
Operating System: Mac OS X (10.4)
I don’t have inDesign available to me right now, but based on your reply, the script is grabbing the objects and recognizing the parent as a page. So we know that’s ok.
Apparently, the script you copied was created for an older version of ID. If you are going to repurpose older scripts you should familiarize yourself with the version differences.
try this and let us know how you make out:
Replace
make group at parent of item 1 of theSel with data theSel
with
make group at parent of item 1 of theSel with properties {group items:{theSel}}
-N
I’ve tried to familiarize myself… downloaded the Indesign pdf. I read and tried the the updated “group items” command with no luck. The code you sent had the same errors come up:
Code:
tell application “InDesign CS”
set myDoc to active document
set a to page width of document preferences of myDoc
set b to page height of document preferences of myDoc
set mySel to selection
if (count of mySel) > 1 then
make group at parent of item 1 of mySel with properties {group items:{mySel}}
end if
move selection to {a / 2, b / 2}
set {w, x, y, z} to geometric bounds of item 1 of mySel
move selection by {-((z - x) / 2), -((y - w) / 2)}
end tell
Event Log:
tell application “InDesign CS”
get active document
document “Untitled-5”
get page width of document preferences of document “Untitled-5”
8.5
get page height of document preferences of document “Untitled-5”
11.0
get selection
{rectangle id 140 of page id 131 of spread id 126 of document “Untitled-5”, rectangle id 139 of page id 131 of spread id 126 of document “Untitled-5”}
make at parent of rectangle id 140 of page id 131 of spread id 126 of document “Untitled-5” with properties {group items:{{rectangle id 140 of page id 131 of spread id 126 of document “Untitled-5”, rectangle id 139 of page id 131 of spread id 126 of document “Untitled-5”}}} new group
“InDesign CS got an error: Invalid parameter.”
So although I’m a newbie, I have done some detective work and tried several commands/read several tutorials. Just can’t get it to work for some reason. I really do appreciate your help, just getting frustrated.
billgates,
Now this is just a theory. I don’t have Indesign here but at work I was looking in the scripting guide pdf from Adobe and I think the syntax for the group thing is as such:
set myGroup to make group with properties {group items:{"item1","item2"}}
So I’m thinking that your selection, mySel, needs to be in the form of a list of items to group which means that you have to get the individual names of each element you want to group and make them a list.
Just a theory.
PreTech,
mySel is in the form of a list, that’s what I wanted to see from my first post. However, due to a silly syntax error (D’oh!) by making a list a list item, things went awry.
Curiousity got the better of me and I DL the trial version of ID CS 2, and by changing:
{group items:{mySel}}
to
{group items:mySel}
everything is working fine.
Have fun Wild BillGates!
-N
Beautiful!! Thank you sooo much guys. You give this forum it’s reputation. I had a new bug arise, but quickly reconciled it. So I guess I’m learning quickly. Here is the final code in case anyone should need it to center objects on a page:
tell application “InDesign CS”
set myDoc to active document
set a to page width of document preferences of myDoc
set b to page height of document preferences of myDoc
set mySel to selection
if (count of mySel) > 1 then
set newSel to make group at parent of item 1 of mySel with properties {group items:mySel}
end if
move newSel to {a / 2, b / 2}
set {w, x, y, z} to geometric bounds of item 1 of newSel
move newSel by {-((z - x) / 2), -((y - w) / 2)}
end tell
PS: nedloh99, how did you know to take out the inner brakets? I found this in the DL’ed “Indesign Scripting Guide”:
set myGroup to make group with properties {group items:{myOval, myRectangle}}
billgates,
“Invalid Parameter” pointed me in the right direction. It was a silly thing I overlooked from the beginning.
set mySel to {myOval, myRectangle} —> you are setting mySel as a list
{group items:{mySel}} —> sets the list mySel as one item in a new list, no go! mySel is already a list.
{group items:mySel} —> keeps the list mySel as just a list.
In english
Group items in this list together: (list item myOval), (list item myRectangle)–> two items make a list
Group items in this list together: (list item (myOval, myRectangle))–>treated as one item in a bigger list.
Hope This Helps
-N