OmniGraffle: Windows

The window class has a few properties:

And two instance functions:

Window: zoom

The percentage of the window display is indicated as a number with 1 representing 100%. For example: 0.75 = 75%, 0.25 = 25%, 2.1 = 210%[0].zoom = 1.0

TIP: to see how to both zoom and center the current canvas to fit in the window, see the example script at the bottom of this page

Window: centerVisiblePoint

The value of the centerVisiblePoint property is the coordinates of the center point of the window view. Keeping in mind that the center point of a shape is represented as a Rect, the window’s centerVisiblePoint property be used to center the current canvas (background shape) in the window:

cnvs =[0].selection.canvas if(cnvs.canvasSizingMode = CanvasSizingMode.Fixed){[0].centerVisiblePoint = }

NOTE: the previous script requires the canvas be set to a fixed size.

And here’s how to center the selected shape in the window:

graphic =[0].selection.solids[0][0].centerVisiblePoint =

OmniGraffle: Document Selection

Working with items selected by the user is a common task performed by scripts. In OmniGraffle, selected document items are identified as elements of the selection property of the frontmost instance of the window class.

var sel =[0].selection

The value of the selection property is a selection object that contains references to important elements of the document. The following examples show how to access references to these items.

Document of the Selection

A reference to the parent document of the selection can be accessed as a property of the selection object:

var doc =[0].selection.document

The Current Canvas

In an OmniGraffle document, there must always be at least one selected canvas. The topmost selected canvas is always considered the current canvas, even if multiple canvases are selected in the window.

var cnvs =[0].selection.canvas

The Current View

The value of the view property of the selection object is an instance of the GraphicView class representing the display of the current canvas of the front window.

var vw =[0].selection.view

The value of the visibleRect property of the canvas view is a Rect defining the view of the canvas in an OmniGraffle window.[0].selection.view.visibleRect

The GraphicView class supports the select function for selecting graphics on the current canvas. Change the selection to a new array of graphics. If the extending parameter is true, then the previous selection is retained as well.[0][arrayOfGraphics],false)

The deselect function removes any of the passed graphics from the current selection, leaving any other currently selected graphics still selected.[0].selection.view.deselect([arrayOfGraphics])

The edit function is used to select the text of solid, initiating the editing mode for the indicated solid.[0].selection.view.edit(solidToEdit)

And here is another example of referencing the GraphicView class to select items, in this case, all graphics in the current canvas:

vw =[0].selection.view cnvs =[0].selection.canvas

Selected Objects

The value of the view property of the the selection object contains arrays of references to these selected objects: graphics, solids, and lines

Selected graphics:

var grphs =[0]
var grphs =[0] for(i = 0; i < grphs.length; i++){ grphs[i]. }

Selected lines:

var lns =[0].selection.lines
var lns =[0].selection.lines for(i = 0; i < lns.length; i++){ lns[i]. }

Selected solids:

var slds =[0].selection.solids
var slds =[0].selection.solids for(i = 0; i < slds.length; i++){ slds[i]. }

Window: setViewForCanvas(…) function and zoom property

Here’s a script that uses the zoom property and setViewForCanvas(…) method of the window class, with the visibleRect property of the view object of the selection class, to zoom the current canvas to fit and center in the current visible window view.

Optionally, you can install it as a plugin.

w =[0] w.zoom = 1 // set zoom to 100% viewSize = w.selection.view.visibleRect.size cnvs = w.selection.canvas cnvsSize = cnvs.size if (cnvs.size.width > cnvs.size.height){ // canvas is landscape if (viewSize.width > viewSize.height){ zoomFactor = viewSize.width / cnvs.size.width } else { zoomFactor = viewSize.width / cnvs.size.width } } else { // canvas is portrait if (viewSize.height > viewSize.width){ zoomFactor = viewSize.width / cnvs.size.width } else { zoomFactor = viewSize.height / cnvs.size.height } } zoomFactor = zoomFactor * 0.95 // reduce 5% w.setViewForCanvas(cnvs, zoomFactor, w.centerVisiblePoint =

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.