hey,
so, what i want to do is center an item over a specific coordinate, namely {500, 430}
if it wasnt clipped, i could just do:
set position of selection to {500 - (t / 2), 430 + (s / 2)}
… but it is. now, i can control the name of the clipping path, so here’s what I have so far…
tell application "Adobe Illustrator"
set t to width of path item "Measurement Box" of document 1
set s to height of path item "Measurement Box" of document 1
set {xSquare1, ySquare1, xSquare2, ySquare2} to visible bounds of path item "Measurement Box" of document 1
set {xArt1, yArt1, xArt2, yArt2} to visible bounds of selection
set theXdifference to xSquare1 - xArt1
set theYdifference to ySquare1 - yArt1
set position of selection to {500 - theXdifference - (t / 2), 430 + theYdifference + (s / 2)}
end tell
but uh… it doesn’t work. i just can’t wrap my head around the math. can anyone figure this out??
thanks guys,
jordan
Are you trying to center the content over this point within the clipping mask?
I’m trying to center the art to a point on the artboard.
The art is entirely clipped, so I want to use the clipping mask’s dimensions.
Otherwise, if I just center the selection, it won’t go
by what’s visible, but rather all the stuff within the clipping mask.
Yeah, this is hard to explain, but does it
make sense now? Also, “visible bounds” in illustrator doesn’t really mean visible. Fun fact.
Thanks,
JG
This should do it for you.
property xp : 500
property yp : 430
tell document 1 of application "Adobe Illustrator"
tell selection
set {{clipW, clipH}, {clipPosX, clipPosY}} to {{width, height}, position} of (first path item whose clipping is true)
set {contentPosX, contentPosY} to position
set position to {xp - (clipW / 2 - (contentPosX - clipPosX)), yp + (clipH / 2 + (contentPosY - clipPosY))}
-- Target point - width / height of the clipping path - (the difference in position between the clipping path and the selection itself)
end tell
end tell
Note this is in CS4 - may need to flip the y value (plus to minus in CS5 with the new origin point).
Also note that you don’t need a named clipping path for this either, in case you forget or have legacy documents without named paths.
The “math” is odd to think about at first but I had to do something similar in a production workflow.
Cheers!
Jim
BLUEFROG
that worked perfectly. thank you.
yeah, the math was confusing, and i played with it until i couldn’t remember what i’d tried. we’re still on CS4 here, but i’ve got CS5 at home so i’ll test it when i get back. i’ve got a lot of scripts that use positions, so it’ll be interesting to see what’s changed.
thanks again!
jg