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
graphics (array of Graphics) • Array of graphics available on the stencil.
images (array of ImageReference) • A list of all images referenced by any graphic in this stencil. Each ImageReference is a unique image and appears only once in the list, even if it is used as the image fill for multiple graphics.
isLoaded (boolean r/o) • Whether or not this stencil has already been loaded into memory.
name (String r/o) • Name of the stencil.
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:
01 | app.stencils.length | |
02 | --> 49 |
Getting the name of a stencil specified by index:
01 | app.stencils[0].name | |
02 | --> Recents |
Call the function below to retrieve the names of all installed stencils:
Get Stencil Names | ||
01 | function getStencilNames(){ | |
02 | var stencilNames = [] | |
03 | app.stencils.forEach(function(aStencil){ | |
04 | stencilNames.push(aStencil.name) | |
05 | }) | |
06 | return stencilNames | |
07 | } |
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:
Get Stencil Names | ||
01 | names = app.stencils.map(function(aStencil){return aStencil.name}) |
The Stencil Object
Call either of the example functions below to retrieve the object reference for a stencil identified by name:
Get Stencil Object by Name | ||
01 | function getStencilObjectByName(stencilName){ | |
02 | var targetStencil | |
03 | app.stencils.forEach(function(aStencil){ | |
04 | if (aStencil.name.localeCompare(stencilName) == 0){ | |
05 | targetStencil = aStencil | |
06 | } | |
07 | }) | |
08 | if (targetStencil instanceof Stencil){ | |
09 | return targetStencil | |
10 | } else { | |
11 | errorString = "There is no stencil named: " + stencilName | |
12 | new Alert('MISSING OBJECT', errorString).show(function(result){}) | |
13 | } | |
14 | } |
Get Stencil Object by Name | ||
01 | // returns a stencil object whose name matches the passed value | |
02 | function getStencilObjectByName(stencilName){ | |
03 | for(i = 0; i < app.stencils.length; i++){ | |
04 | if (app.stencils[i].name.localeCompare(stencilName) == 0){ | |
05 | return app.stencils[i] | |
06 | } | |
07 | } | |
08 | errorString = "There is no stencil named: " + stencilName | |
09 | new Alert('ERROR', errorString).show() | |
10 | throw new Error(errorString) | |
11 | } |
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.
Create Shape with Stencil Names | ||
01 | names = app.stencils.map(function(aStencil){return aStencil.name}) | |
02 | names = names.sort() | |
03 | cnvs = document.windows[0].selection.canvas | |
04 | var shape = cnvs.newShape() | |
05 | shape.autosizing = TextAutosizing.Full | |
06 | shape.textHorizontalAlignment = HorizontalTextAlignment.Left | |
07 | 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.