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 Omni Automation, 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”


Another way to access the names of the installed stencils, is to use the JavaScript map method. This method is particularly useful and efficient in retrieving object properties:

stencilNames ={return})

The Stencil Object

Call either of the example functions below to retrieve the object reference for a stencil identified by name:

function getStencilObjectByName(stencilName){ var targetStencil app.stencils.forEach(function(aStencil){ if ( == 0){ targetStencil = aStencil } }) if (targetStencil instanceof Stencil){ return targetStencil } else { errorString = "There is no stencil named: " + stencilName new Alert('MISSING OBJECT', errorString).show(function(result){}) } }
// returns a stencil object whose name matches the passed value function getStencilObjectByName(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. The script uses the JavaScript map(), join(), and sort() methods, as well as the Omni Automation newShape() method.

names ={return}) names = names.sort() cnvs =[0].selection.canvas var shape = cnvs.newShape() shape.autosizing = TextAutosizing.Full shape.textHorizontalAlignment = HorizontalTextAlignment.Left shape.text = names.join('\n')

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