Hi
I’m trying to find some code to center items on a page, and not having much luck, the page items are placed and in a group, and selected, basically the group just needs to be centered, the page size will vary.
does any one have some code they can share or point me to please
Budgie. this is fairly simple stuff. Although Adobe’s logic is sometimes not. AI CS5 & CS6 work from Top/Left using negative values down. Here is a sample that may work for you. This one does not account for stroked items if you need that then it will need re-wording slightly.
tell application "Adobe Illustrator"
tell the current document
-- Get the first artboard
set artB to the artboard rectangle of first artboard
set artW to item 3 of artB
set artH to -(item 4 of artB) -- This becomes integer don't know why
-- Get the first group.
set grpB to the geometric bounds of first group item
set grpW to (item 3 of grpB) - (item 1 of grpB)
set grpH to -((item 4 of grpB) - (item 2 of grpB))
-- Move top/Left of your group to
set position of the first group item to ¬
{(artW - grpW) / 2, -((artH - grpH) / 2)}
end tell
end tell
artH -- This becomes integer don't know why???????
artW -- This remains as real number
There does appear to be an issue with AppleScript and make a value negative not sure why.? Did I forget a proper way?
the code centers everything on the x axis fine, but centers on the y axis in the middle of the item at the bottom of the page, not centered as expected?
I don’t think it was wrong, it just didn’t end up doing what was needed here. I’m slotting some illustrator actions into my ASOC app and for what ever reason it just would not center on the y axis, so to remedy this I changed this line
et artH to -(item 4 of artB) -- This becomes integer don't know why
to this
set artH to - (Page_H * mm)
where Page_H is pulled from a text fiels and mm is a property
property mm : 2.834645 as number
and i’m a happy camper,
I got hung up trying to use this type of set up, and wasnt getting the results I was after
set myMatrix to (get identity matrix)
set myMatrix to concatenate translation matrix myMatrix delta x mymoveX delta y mymoveY
Oh thats OK then. I have CS5 where Adobe turned the co-ords on its head as long as they have not u-turned a version later. There is also the issue where the co-ords differ with an opening a document and a new script created document and it can be confusing when testing debugging.