Guest
2011-12-19, 03:46 PM
Here is a rough Zoom to Fit:
NOTE Now replaced by an improved script in its
own thread.
Code:
-- ROUGH OMNIGRAFFLE ZOOM TO FIT
-- VER 0.3
-- ADJUST pZoomFactor up or down to suit
property pZoomFactor : 0.8
tell application id "OGfl"
tell front window
set {rX, rY, rX1, rY1} to bounds
set {rWinWidth, rWinHeight} to {rX1 - rX, rY1 - rY}
try
set oFrontCanvas to its canvas
on error
return
end try
repeat with oCanv in canvases of its document
set {lstOrigin, lstSize} to {origin, size} of graphics of oCanv
set lngGraphics to length of lstOrigin
if lngGraphics > 0 then
set {rXMax, rYMax} to {0, 0}
repeat with i from 1 to lngGraphics
set {rX, rY} to item i of lstOrigin
set {rWidth, rHeight} to item i of lstSize
set {rXPosn, rYPosn} to {rX + rWidth, rY + rHeight}
if rXPosn > rXMax then set rXMax to rXPosn
if rYPosn > rYMax then set rYMax to rYPosn
end repeat
set {rXScale, rYScale} to {rWinWidth / rXMax, rWinHeight / rYMax}
set canvas of it to oCanv
if rXScale < rYScale then
set zoom to rXScale * pZoomFactor
else
set zoom to rYScale * pZoomFactor
end if
end if
end repeat
set its canvas to oFrontCanvas
end tell
end tell
Last edited by RobTrew; 2011-12-20 at 07:29 AM..
Reason: Edited code to avoid division by zero with empty canvases