The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Applescript: How to use stencil, magnet (http://forums.omnigroup.com/showthread.php?t=27281)

Sophie 2012-12-03 08:56 PM

Applescript: How to use stencil, magnet
 
Using Applescript, how do I access / instantiate shapes from a stencil onto a working document canvas?

Also, if some of my shapes have magnets on them, how do I create a line between magnet1 on shape 1, and magnet5 on shape 2, using Applescript?

Thanks!

RobTrew 2012-12-05 04:39 AM

[QUOTE=Sophie;118024]access / instantiate shapes from a stencil[/QUOTE]

My understanding is that stencils are beyond the reach of the current Applescript library.

[QUOTE=Sophie;118024]
how do I create a line between magnet1 on shape 1, and magnet5 on shape 2, using Applescript?[/QUOTE]

The connect command doesn't let us specify source or target magnets. We can, however, change the number and position of the magnets at run-time.

When rotating a vertical tree into a horizontal tree, for example (leaving the text nodes unrotated), I use script to reduce the number of magnets to two per shape, and flip them from North + South to East + West.

john.gersh 2012-12-06 10:29 AM

While the connect command does ignore head magnet and tail magnet properties, this seems to be a case where setting the properties as a second step works. For example:


[CODE]tell application "OmniGraffle Professional 5"

tell canvas of front window
set firstShape to make new shape at end of graphics with properties {draws shadow:false, size:{100, 100}, origin:{50, 50}, magnets:{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}, thickness:3}

set secondShape to make new shape at end of graphics with properties {name:"Circle", draws shadow:false, size:{100, 100}, origin:{200, 200}, magnets:{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}, thickness:3}

end tell

set theLine to connect firstShape to secondShape with properties {thickness:2.0, line type:orthogonal, head type:"FilledArrow"}
set head magnet of theLine to 4
set tail magnet of theLine to 1

end tell[/CODE]

It also works with pre-existing shapes.

You do see the process of drawing and then changing as two visual steps. If that's a problem you can make the original thickness of the line zero and then set it to something else after setting the magnets.

RobTrew 2012-12-06 10:00 PM

Good point, and even if you are doing this by working with shape properties rather than line properties (setting shape magnet positions rather than setting the head/tail magnets of lines), you may still need to explicitly clear any pre-existing head/tail magnet settings.

Rotated trees:
[CODE]property plstEastWest : {{1.0, 0.0}, {-1.0, 0.0}}
property plstNorthSouth : {{0.0, -1.0}, {0.0, 1.0}}
property plstMagnets : {plstEastWest, plstNorthSouth}

property plstHorizOrigins : {{275, 225}, {400, 170}, {400, 275}}
property plstVertOrigins : {{620, 160}, {675, 280}, {570, 280}}
property plstOrigins : {plstHorizOrigins, plstVertOrigins}


tell application id "OGfl"
set recLineProps to {line type:orthogonal, stroke color:{1.0, 0.0, 0.0}}
tell canvas of front window
set {iFirst, iLast} to {1, 3}
repeat with i from 1 to 2
set lstOrigins to item i of plstOrigins

-- EAST WEST IN FIRST CASE, THEN NORTH SOUTH
set lstMagnets to item i of plstMagnets

-- MAKE THE SHAPES
repeat with j from 1 to 3
make new shape at end of graphics with properties {corner radius:5, draws stroke:false, size:{90, 90}, origin:item j of lstOrigins, magnets:item i of plstMagnets}
end repeat

-- AND MAKE THE CONNECTIONS
set {shpParent, shpChild, shpSibling} to items iFirst thru iLast of (shapes as list)
connect shpParent to shpChild with properties recLineProps
connect shpParent to shpSibling with properties recLineProps

-- IN SOME CASES YOU MAY NEED TO CLEAR ANY PRE-EXISTING HEAD OR TAIL MAGNET SETTINGS
-- AS A PRECAUTION
tell lines to set {head magnet, tail magnet} to {0, 0}

-- PREPARE FOR NEXT LOOP
set {iFirst, iLast} to {iFirst + 3, iLast + 3}
end repeat
end tell
end tell
[/CODE]


All times are GMT -8. The time now is 10:34 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.