Re: Illustrator CS4 hierarchical menus
Re: Illustrator CS4 hierarchical menus
- Subject: Re: Illustrator CS4 hierarchical menus
- From: Shane Stanley <email@hidden>
- Date: Thu, 16 Sep 2010 09:57:00 +1000
- Thread-topic: Illustrator CS4 hierarchical menus
On 16/9/10 3:19 AM, "John C. Welch" <email@hidden> wrote:
> The closest I could get to ³correct² was with this:
>
> tell application "Adobe Illustrator"
> set theDoc to current document
> set selected of (every page item of theDoc) to true
> scale selection horizontal scale 50.0 vertical scale 50.0 about document
> origin with transforming objects
> end tell
>
> And all that did was preserve relative object positioning, not window
> position. If someone here knows someone from the Illustrator team, or someone
> from that team is on the list, maybe they know of a way to handle this?
You're on the right track -- you just need to reposition things after the
move. To do that, you need to know the bounds of the selected stuff so you
can work out its width, height, etc. Unfortunately, when you ask for the
bounds of the selection, you get the bounds of the first page item in the
selection.
You can get the bounds of all the selected page items and calculate the
overall bounds from there:
set theScale to 50
tell application "Adobe Illustrator"
tell document 1
set allBounds to geometric bounds of page items whose selected is
true
set {x1, y1, x2, y2} to my overallBounds(allBounds)
scale selection horizontal scale theScale vertical scale theScale
about document origin with transforming objects
translate selection delta x (x1 + (x2 - x1) / 2) * (100 - theScale)
/ 100 delta y (y1 + (y2 - y1) / 2) * (100 - theScale) / 100
end tell
end tell
return overallBounds(allBounds)
on overallBounds(allBounds)
set {x1, y1, x2, y2} to item 1 of allBounds
set allBounds to rest of allBounds
repeat with oneBounds in allBounds
if item 1 of oneBounds < x1 then set x1 to item 1 of oneBounds
if item 2 of oneBounds > y1 then set y1 to item 2 of oneBounds
if item 3 of oneBounds > x2 then set x2 to item 3 of oneBounds
if item 4 of oneBounds < y1 then set y2 to item 4 of oneBounds
end repeat
return {x1, y1, x2, y2}
end overallBounds
It's easy enough, but very slow if there are a lot of items. A faster way is
to make a new group from the selection, get its bounds, then undo:
set theScale to 50 -- whatever
tell application "Adobe Illustrator"
-- get bounds of selection
tell document 1
set tempGroup to make group item at beginning
move selection to tempGroup
set {x1, y1, x2, y2} to geometric bounds of tempGroup
end tell
undo -- the grouping
undo -- the making of the group
-- scale and put back
tell document 1
scale selection horizontal scale theScale vertical scale theScale
about document origin with transforming objects
translate selection delta x (x1 + (x2 - x1) / 2) * (100 - theScale)
/ 100 delta y (y1 + (y2 - y1) / 2) * (100 - theScale) / 100
end tell
end tell
--
Shane Stanley <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden