The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Applescript: How to use stencil, magnet Thread Tools Search this Thread Display Modes
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!
 
Quote:
Originally Posted by Sophie View Post
access / instantiate shapes from a stencil
My understanding is that stencils are beyond the reach of the current Applescript library.

Quote:
Originally Posted by Sophie View Post
how do I create a line between magnet1 on shape 1, and magnet5 on shape 2, using Applescript?
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.
 
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
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.

Last edited by john.gersh; 2012-12-06 at 10:36 AM..
 
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
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to have one magnet for each line of text? StTheo OmniGraffle General 0 2013-04-20 06:59 AM
Copy Magnet link URL bug Drayon OmniWeb Bug Reports 1 2013-01-11 12:42 PM
How to stick to individual magnet HappyCatMachine OmniGraffle for iPad 1 2011-02-22 02:01 AM
Magnet tool help needed Technopatra OmniGraffle General 3 2008-01-10 05:25 PM
Magnet layout DavidA OmniGraffle General 0 2007-08-10 07:48 AM


All times are GMT -8. The time now is 07:46 AM.


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