OmniGraffle: Stencils

A stencil is a reusable shape that can be dragged to the canvas from the Stencils window. Stencils can be as simple as a square or triangle, or as complex as a multilayered and meticulously designed illustration. Each object or object group in an OmniGraffle stencil file becomes an individual stencil.

TIP: As a service to OmniGraffle users, the Omni Group hosts STENCILTOWN, a website from which you can download and install stencil files containing very useful collections of stencil graphics.

Stencil Properties

The Stencil Object (stencil file)

In scripting parlance, a stencil refers to a stencil file, and it is an element of the application class. A stencil is a container holding a defined set of graphics you can add to your OmniGraffle document.

In OmniJS, the OmniGraffle stencil class has a property (name) and elements (graphics).

Determining how many stencils (stencil files) are installed:

Getting the name of a stencil specified by index:

Call the function below to retrieve the names of all installed stencils:

function getStencilNames(){ var stencilNames = [] app.stencils.forEach(function(aStencil){ stencilNames.push(aStencil.name) }) return stencilNames }
omnigraffle:///omnijs-run?script=function%20getStencilNames()%7B%0A%09var%20stencilNames%20%3D%20%5B%5D%0A%09app.stencils.forEach(function(aStencil)%7B%0A%09%09stencilNames.push(aStencil.name)%0A%09%7D)%0A%09return%20stencilNames%0A%7D%0AgetStencilNames()

The result of calling the function above in the OmniGraffle console window (see below) will be a list of the names of the installed stencils:

“Recents”, “Connections”, “Shapes”, “UX Kits Colors”, “Solarized Dark”, “Solarized Light”, “UX Kits UML”, “UX Kits Connections”, “Square Foot Gardening”, “Modern Landscape”, “Flowers”, “Reference”, “Africa”, “Colors”, “Fills”, “USA”, “Periodic Table”, “Rounded Corners”, “Mac OS X Wireframes”, “Magnetized”, “FlowChart”, “Furniture”, “Konigi Wireframes”, “UML-State”, “Antarctica”, “Asia Pacific”, “Russia”, “Middle East”, “Plumbing Fixtures”, “Walls, Windows & Doors”, “North America”, “Boolean Gates”, “Circuit Engineering”, “Connections”, “Appliances”, “UML-UseCase”, “UML-General”, “Fonts”, “South America”, “UML-Sequence”, “Europe”, “Turkey”, “Russia”, “Ukraine”, “Garrett IA”, “Three-Dimensional”, “ERD”, “iOS Wireframes”, “Shapes”, “Apple watchOS Suite”, “The iOS 9 Suite”, “UX Kits UML”, “Google Material Design Icons”, “UX Kits Hardware”

change-color-of-selection

The Stencil Object

Call the function below to retrieve the object reference for a stencil identified by name:

// returns a stencil object whose name matches the passed value function getNamedStencil(stencilName){ for(i = 0; i < app.stencils.length; i++){ if (app.stencils[i].name.localeCompare(stencilName) == 0){ return app.stencils[i] } } errorString = "There is no stencil named: " + stencilName // new Alert('ERROR', errorString).show(function(result){}) throw new Error(errorString) }

To enable visual error reporting, uncomment the line containing the alert command (09) to have the function display a dialog if no matching stencil can be located:

alert-dialog-01

Example Script

Here is an example script that will create a new text shape containing the names of the installed stencils:

function getStencilNames() { var stencilNames = [] app.stencils.forEach(function(aStencil){ stencilNames.push(aStencil.name) }) return stencilNames } function shapeWithContentsOfArray(arrayOfStrings){ cnvs = document.windows[0].selection.canvas var aShape = cnvs.newShape() aShape.autosizing = TextAutosizing.Full aShape.text = arrayOfStrings.join('\n') return aShape } var names = getStencilNames() shapeWithContentsOfArray(names)
omnigraffle:///omnijs-run?script=function%20getStencilNames%28%29%20%7B%0A%09var%20stencilNames%20%3D%20%5B%5D%0A%09app%2Estencils%2EforEach%28function%28aStencil%29%7B%0A%09%09stencilNames%2Epush%28aStencil%2Ename%29%0A%09%7D%29%0A%09return%20stencilNames%0A%7D%0Afunction%20shapeWithContentsOfArray%28arrayOfStrings%29%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09var%20aShape%20%3D%20cnvs%2EnewShape%28%29%0A%09aShape%2Eautosizing%20%3D%20TextAutosizing%2EFull%0A%09aShape%2Etext%20%3D%20arrayOfStrings%2Ejoin%28%27%5Cn%27%29%0A%09return%20aShape%0A%7D%0Avar%20names%20%3D%20getStencilNames%28%29%0AshapeWithContentsOfArray%28names%29
UNDER CONSTRUCTION

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

DISCLAIMER