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

 
Script: Zoom all canvases to fit whole diagram Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
A draft script:

Code:
-- ZOOM ALL CANVASES IN CURRENT OMNIGRAFFLE DOCUMENT TO FIT WHOLE DIAGRAM

property pTitle : "Zoom All Canvases to Fit"
property pVer : "0.8"

property plstMenuItem : {"View", "Zoom", "Zoom to Selection"}

-- ADJUST THIS TO A VALUE SLIGHTLY BELOW 1.0 TO DECREASE THE DEFAULT LEVEL OF ZOOM
property pZoomScale : 0.9

on run
	if not GUIEnabled() then return
	
	-- GET A REFERENCE TO VIEW > ZOOM > ZOOM TO SELECTION
	set mnuZoomFit to GetMenuItem("OGfl", plstMenuItem)
	
	-- LOOP THRU EACH CANVAS, 
	--    SELECTING ALL GRAPHICS AND ZOOMING TO SELECTION, 
	-- 	AND ALLOWING FOR A FRACTIONAL ADJUSTMENT OF THE DEGREE OF ZOOM
	--     (THEN RESTORE ORIGINAL SELECTION)
	tell application id "OGfl"
		activate
		tell front window
			try
				set oFrontCanvas to its canvas
			on error
				return
			end try
			
			repeat with oCanv in canvases of its document
				set canvas of it to oCanv
				
				-- RECORD EXISTING SELECTION
				set lstSeln to its selection
				
				-- ZOOM TO FIT WHOLE DIAGRAM
				set its selection to graphics of oCanv
				tell application id "sevs" to click mnuZoomFit
				if pZoomScale ≠ 1.0 then set its zoom to (its zoom) * pZoomScale
				
				-- RESTORE ORIGINAL SELECTION
				set its selection to lstSeln
			end repeat
			set its canvas to oFrontCanvas
		end tell
	end tell
end run


-- RETURNS A REFERENCE TO A CLICKABLE MENU ITEM
-- E.G. set mnuZoomFit to GetMenuItem("OGfl", {"View", "Zoom", "Zoom to Selection"})
on GetMenuItem(strAppCode, lstMenu)
	set lngChain to length of lstMenu
	if lngChain < 2 then return missing value
	
	tell application id "sevs"
		set lstApps to application processes where its creator type = strAppCode
		if length of lstApps < 1 then return missing value
		tell first item of lstApps
			-- GET THE TOP LEVEL MENU
			set strMenu to item 1 of lstMenu
			set oMenu to menu strMenu of menu bar item strMenu of menu bar 1
			
			-- TRAVEL DOWN THROUGH ANY SUB-MENUS
			repeat with i from 2 to (lngChain - 1)
				set strMenu to item i of lstMenu
				set oMenu to menu strMenu of menu item strMenu of oMenu
			end repeat
			
			-- AND RETURN THE FINAL MENU ITEM
			return menu item (item -1 of lstMenu) of oMenu
		end tell
	end tell
end GetMenuItem

on GUIEnabled()
	tell application id "sevs"
		if UI elements enabled then
			return true
		else
			activate
			display dialog "This script depends on enabling access for assistive devices in system preferences" buttons "OK" default button "OK" with title pTitle & "   " & pVer
			tell application id "sprf"
				activate
				set current pane to pane id "com.apple.preference.universalaccess"
			end tell
			return false
		end if
	end tell
end GUIEnabled

Last edited by RobTrew; 2011-12-21 at 11:03 AM.. Reason: Ver 0.8 generalizes GUI access to items nested in submenus
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global zoom level for multiple canvases chrishan OmniGraffle General 6 2013-01-24 03:22 PM
Script: Export from FoldingText outline to OmniGraffle diagram RobTrew OmniGraffle General 0 2012-10-04 12:44 PM
how do I break process diagram into separate pages and display diagram name on every page Chien OmniGraffle General 0 2012-04-25 06:38 AM
Is there any way to set zoom across multiple canvases? fjordaan OmniGraffle General 7 2011-08-24 05:32 AM
multiple master canvases, new canvases wynntemp OmniGraffle General 2 2009-02-23 01:44 PM


All times are GMT -8. The time now is 01:54 AM.


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