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( }) return stencilNames }

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”


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:


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( }) return stencilNames } function shapeWithContentsOfArray(arrayOfStrings){ cnvs =[0].selection.canvas var aShape = cnvs.newShape() aShape.autosizing = TextAutosizing.Full aShape.text = arrayOfStrings.join('\n') return aShape } var names = getStencilNames() shapeWithContentsOfArray(names)

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