Applescript first steps. Joining shapes with a curvy line??
Wim Lewis
wiml at omnigroup.com
Wed Nov 7 10:54:32 PST 2007
On Nov 7, 2007, at 12:01 AM, <christian.sodl at orf.at> wrote:
> Hi,
> There is a connect command in the OG Applescript Directory.
>
[...]
> Also you can add with properties {line type:curved,....} to specify
> some parameters of the generated lines.
In addition, the "connect" command (like most of the commands that
create objects) returns the newly-created object, so it's possible to
write a script like this:
set A to (connect the first solid to the last solid) -- A is
now a reference to the line
set the thickness of A to 3.0
set the stroke color of A to {1.0, 0.0, 0.0}
It's also possible to make connections without using the "connect"
command:
tell the first canvas of the first document
set A to (make new line with properties {thickness:3.0, stroke
color:{1.0, 0.0, 0.0}, line type:curved})
set the point list of A to {{0, 0}, {200, 200}, {0, 0}
set the source of A to (the first solid) -- modifies the first
point as a side-effect
set the destination of A to (the last solid) -- modifies the
last point as a side-effect
return (the point list of A as list) -- to show you the
points of the line
end tell
On Oct 31, 2007, at 4:10 AM, Ivan Rostas wrote:
> Could anyone give me a gentle push-off the pier by describing the
> Applescript required to have a curvy line link a number of
> highlighted objects? Say I multiple select some objects on screen,
> I would like to have a 'button' in the bottom corner of the page
> with an Action that runs a little Applescript to have a curvy (sine-
> like?) line link the objects - however not link back to the first
> object. That will be done manually, so I stay alert.
The hard part is making the lines curvy, since the script will need
to choose coordinates for the midpoints of the curvy lines. To choose
a midpoint for a curvy line, you could, for example, get the center
of the each "source" graphic and "destination" graphic, average their
coordinates to get a point in between the two graphics, and add
something to the Y-coordinate to make the line curve upwards a bit.
Here's a quick try at doing that:
tell the first window
set Things to (get the selection as list)
tell the canvas of it
repeat with Ix from 1 to (the (count of Things) - 1)
set FromGraphic to item Ix of Things
set ToGraphic to item (Ix + 1) of Things
set FromXY to the origin of FromGraphic
set ToXY to the origin of ToGraphic
set MidXY to {(the (first item of FromXY) + the (first
item of ToXY)) / 2.0, (the (second item of FromXY) + the (second item
of ToXY)) / 2.0 + 20.0}
connect FromGraphic to ToGraphic with properties {line
type:curved, stroke color:{0.0, 0.0, 1.0}, point list:{{0, 0}, MidXY,
{0, 0}}}
end repeat
end tell
end tell
The midpoints aren't quite in the right place because I'm using the
"origin" (upper-left corner) of each graphic instead of the center
(where the line will connect). But this should give you the general
idea. You could instead get the first and last points of the line
*after* connecting it and average those, instead of getting the
locations of the graphics, for example.
More information about the OmniGraffle-Users
mailing list