OmniGraffle: Stencil Graphics

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. However, in scripting terms, each stencil in the stencil file is referred to as a graphic.

So with that in mind, an important function of the scripting support in OmniGraffle is to automate the process of locating and importing stencil graphics into your documents. This page contains routines for performing those functions.

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.

What graphics are in a stencil?

A basic script task is to identify, by name, the graphics within a stencil.

To get information about the graphics in a stencil, the stencil file must first be read into memory by the OmniGraffle application so that the stencil’s contents can be examined. This is done using the load() method, which has as its direct parameter, a callback function. When the stencil file has been read by the application, the callback function will be executed.

The callback function iterates the list of stencil graphics and each is queried for the value of its name property. After querying each graphic, the resulting array is returned as the result of the main function.

function getGraphicNamesForNamedStencil(stencilName){ var stencilNames = new Array() app.stencils.forEach(function(aStencil){ stencilNames.push(aStencil.name) }) if(stencilNames.indexOf(stencilName) == -1){ throw new Error("There is no stencil named: " + stencilName) } var graphicNames = new Array() for(i = 0; i < app.stencils.length; i++) { let stencil = app.stencils[i] if (stencil.name.localeCompare(stencilName) == 0) { stencil.load(function(s) { console.log("Loaded stencil: “" + s.name + "”") stencil.graphics.forEach(function(aGraphic){ graphicNames.push(aGraphic.name) }) return graphicNames }) } } return graphicNames }
function getGraphicNamesForStencil(stencilName){ // get the names of every stencil var stencilNames = app.stencils.map(function(aStencil){ return aStencil.name }) // does the list of stencil names contain the stencil name? if(stencilNames.indexOf(stencilName) === -1){ throw new Error("There is no stencil named: " + stencilName) } // get a reference to the target stencil var targetStencil app.stencils.forEach(function(aStencil){ if (aStencil.name === stencilName){targetStencil = aStencil} }) var graphicNames targetStencil.load(function(stencilRef){ console.log("Loaded stencil: “" + stencilRef.name + "”") graphicNames = stencilRef.graphics.map(function(aGraphic){ return aGraphic.name }) return graphicNames }) if (graphicNames){ return graphicNames } else { throw new Error("Problem reading graphic names from stencil: " + stencilName) } }

The result of using the function shown above to identify all of the graphics in the Google Material Design Icons stencil would be:

"Star Outline", "Star Half", "Star", "Radio Button On", "Radio Button Off", "Checkbox Outline Blank", "Checkbox", "What's Hot", "Share", "School", "Public", "Poll", "Plus One", "Person Outline", "Person Add", "Person", "People Outline", "People", "Party Mode", "Pages", "Notifications Paused", "Notifications On", "Notifications Off", "Notifications None", "Notifications", "Mood", "Location City", "Group Add", "Group", "Domain", "Cake", "", "VPN Lock", "Voice Chat", "Vibration", "Time to Leave", "Tap and Play", "System Update", "Sync Problem", "Sync Disabled", "Sync", "SMS Failed", "SMS", "Sim Card Alert", "SD Card", "Play Install", "Play Download", "Phone Paused", "Phone Missed", "Phone Locked", "Phone In Talk", "Phone Forwarded", "Phone Bluetooth Speaker", "Network Locked", "More", "MMS", "Folder Special", "Event Note", "Event Busy", "Event Available", "Drive ETA", "Do Not Disturb", "DND Forward Slash", "Disc Full", "Bluetooth Audio", "ADB", "", "Unfold More", "Unfold Less", "Refresh", "More Vert", "More Horiz", "Menu", "Fullscreen Exit", "Fullscreen", "Expand More", "Expand Less", "Close", "Chevron Right", "Chevron Left", "Check", "Cancel", "Arrow Forward", "Arrow Drop Up", "Arrow Drop Down Circle", "Arrow Drop Down", "Arrow Back", "Apps", "", "Traffic", "Terrain", "Store Mall Directory", "Satellite", "Restaurant Menu", "Rate Review", "Place", "Pin Drop", "Navigation", "My Location", "Map", "Location History", "Local Taxi", "Local Shipping", "Local See", "Local Restaurant", "Local Print Shop", "Local Post Office", "Local Play", "Local Pizza", "Local Phone", "Local Pharmacy", "Local Parking", "Local Offer", "Local Movies", "Local Mall", "Local Library", "Local Laundry Service", "Local Hotel", "Local Hospital", "Local Grocery Store", "Local Gas Station", "Local Florist", "Local Drink", "Local Convenience Store", "Local Car Wash", "Local Cafe", "Local Bar", "Local Attraction", "Local ATM", "Local Airport", "Layers Clear", "layers", "Hote;", "Flight", "Directions Walk", "Directions Transit", "Directions Train", "Directions Subway", "Directions Ferry", "Directions Car", "Directions Bus", "Directions Bike", "Directions", "Been Here", "", "WB Sunny", "WB Irradescent", "WB Incandescent", "WB Cloudy", "WB Auto", "Tune", "Transform", "Tonality", "Timer Off", "Timer Auto", "Timer 3", "Timer", "Timer 10", "Time Lapse", "Texture", "Tag Faces", "Switch Video", "Switch Camera", "Style", "Straighten", "Slideshow", "Rotate Right", "Rotate Left", "Remove Red Eye", "Portrait", "Photo Library", "Photo Camera", "", "Photo Album", "Photo", "Panorama Wide Angle", "Panorama Vertical", "Panorama Horizontal", "Panorama Fisheye", "Panorama", "Palette", "Navigate Next", "Navigate Before", "Nature People", "Nature", "Movie Creation", "Loupe", "Looks 2", "Looks 1", "Looks 6", "Looks 5", "Looks 4", "Looks 3", "Looks", "Lens", "Leak Remove", "Leak Add", "Landscape", "ISO", "Image Aspect Ratio", "Image", "Healing", "HDR Weak", "HDR Strong", "HDR On", "HDR Off", "Grid On", "Grid Off", "Grain", "Gradient", "Flip", "Flash On", "Flash Off", "Flash Auto", "Flare", "Filter Vintage", "Filter Tilt Shift", "Filter None", "Filter HDR", "Filter Frames", "Filter Drama", "Filter Center Focus", "Filter B and W", "Filter 9 Plus", "Filter 9", "Filter 8", "Filter 7", "Filter 6", "Filter 5", "Filter 4", "Filter 3", "Filter 2", "Filter", "Filter 1", "Exposure Zero", "Exposure Plus 2", "Exposure +1", "Exposure -2", "Exposure -1", "Exposure", "Edit", "Details", "Dehaze", "Crop Square", "Crop Portrait", "Crop Original", "Crop Landscape", "Crop Free", "Crop Din", "Crop 7 5", "Crop 5 4", "Crop 3 2", "Crop", "Crop 16 9", "Control Point Duplicate", "Control Point", "Compare", "Colorize", "Color Lens", "Collections", "Center Focus Weak", "Center Focus Strong", "Camera Roll", "Camera Rear", "Camera Front", "Camera Alt", "", "Camera", "Brush", "Brightness 7", "Brightness 6", "Brightness 5", "Brightness 4", "Brightness 3", "Brightness 2", "Brightness 1", "Blur On", "Blur Off", "Blur Linear", "Blur Circular", "Audiotrack", "Assistant Photo", "Adjust", "Add To Photos", "", "Watch", "TV", "Tablet Mac", "Tablet Android", "Tablet", "Speaker", "Smartphone", "SIM Card", "Security", "Phone Link Off", "Phone Link", "Phone iPhone", "Phone Android", "Mouse", "Memory", "latop Windows", "Laptop Mac", "Laptop Chromebook", "Laptop", "Keyboard Voice", "Keyboard Tab", "Keyboard Return", "Keyboard Hide", "Keyboard Control", "Keyboard Capslock", "Keyboard Backspace", "Keyboard Arrow Up", "Keyboard Arrow Right", "", "Keyboard Arrow Down", "Keyboard Alt", "Keyboard", "Headset Mic", "Headset", "Gamepad", "Dock", "Desktop Windows", "Desktop Mac", "Computer", "Cast Connected", "Cast", "", "Folder Shared", "Folder Open", "Folder", "File Upload", "File Download", "Cloud Upload", "Cloud Queue", "Cloud Off", "Could Download", "Cloud Done", "Cloud Circle", "Cloud", "Attachment", "", "Wrap Text", "Vertical Align Top", "Vertical Align Center", "Vertical Align Bottom", "Publish", "Mode Edit", "Mode Comment", "Merge Type", "Insert Photo", "Insert Link", "Insert Invitation", "Insert Emoticon", "Insert Drive File", "Insert Comment", "Insert Chart", "Functions", "Format Underline", "Format Text Direction R to L", "Format Text Direction L to R", "Format Strikethrough", "Format Size", "Format Quote", "Format Paint", "Format List Numbered", "Format List Bulleted", "Format Line Spacing", "Format Italic", "Format Indent Increase", "Format Indent Decrease", "Format Color Text", "Format Color Reset", "Format Color Fill", "Format Clear", "Format Bold", "Format Align Right", "Format Align Left", "Format Align Justify", "Formal Align Center", "Border Vertical", "", "Border Style", "Border Right", "Border Outer", "Border Left", "Border Inner", "Border Horizontal", "Border Color", "Border Clear", "Border Bottom ", "Border All", "Attach Money", "Attach File", "", "WiFi Tethering", "WiFi Lock", "USB", "Storage", "Signal WiFi Statusbar Null", "Signal WiFi Statusbar Not Connected", "Signal WiFi Statusbar Connected No Internet 4", "Signal WiFi Statusbar Connected No Internet 3", "Signal WiFi Statusbar Connected No Internet 2", "Signal WiFi Statusbar Connected No Internet", "Signal WiFi Statusbar Connected No Internet 1", "Signal WiFi Statusbar 4 Bar", "Signal WiFi Statusbar 3 Bar", "Signal WiFi Statusbar 2 Bar", "Signal WiFi Statusbar 1 Bar", "", "Signal WiFi Off", "Signal WiFi 4 Bar", "Signal WiFi 3 Bar", "Signal WiFi 2 Bar", "Signal WiFi 1 Bar", "Signal WiFi 0 Bar", "Signal Cellular Off", "Signal Cellular Null", "Signa; Cellular No SIM", "Signal Cellular Connected No Internet 4 Bar", "Signal Cellular Connected No Internet 3 Bar", "Signal Cellular Connected No Internet 2 Bar", "", "Signal Cellular Connected No Internet 0 Bar", "Signal Cellular 4 Bar", "Signal Cellular 3 Bar", "Signal Cellular 2 Bar", "Signal Cellular 1 Bar", "Signal Cellular 0 Bar", "Settings System Daydream", "SD Storage", "Screen Rotation", "Screen Lock Rotation", "Screen Lock Portrait", "Screen Lock Landscape", "Now Widgets", "Now Wallpaper", "NFC", "Network WiFi", "Network Cell", "Multitrack Audio", "Location Searching", "Location Disabled", "GPS Off", "GPS Not Fixed", "GPS Fixed", "DVR", "Devices", "Developer Mode", "Data Usage", "Brightness Medium", "Brightness Low", "Brightness High", "Brightness Auto", "Bluetooth Searching", "Bluetooth Disabled", "Bluetooth Connected", "Bluetooth", "Battery Unknown", "Battery Std", "Battery Full", "Battery Charging Full", "", "Battery Charging 80", "Battery Charging 60", "Battery Charging 50", "Battery Charging 30", "Battery Charging 20", "Battery Alert", "Battery 90", "Battery 80", "Battery 60", "Battery 50", "Battery 30", "Battery 20", "Airplane Mode On", "Airplane Mode Off", "Add Alarm", "Access Time", "Access Alarms", "Access Alarm", "", "Undo", "Text Format", "Sort", "Send", "Select All", "Save", "Report", "Reply All", "Reply", "Remove Circle Outline", "Remove Circle", "Remove", "Redo", "Mark Unread", "Mail", "Link", "Inbox", "Gester", "Forward", "Flag", "Filter List", "Drafts", "Create", "Content Paste", "Content Cut", "Content Copy", "Clear", "Block", "Backspace", "Archive", "Add Circle Outline", "Add Circle", "Add Box", "Add", "", "VPN Key", "Voicemail", "Text SMS", "Swap Calls", "Stay Primary Portrait", "Stay Primary Landscape", "Stay Current Portrait", "Stay Current Landscape", "Ring Volume", "Quick Contacts Mail", "Quick Contacts Dialer", "Portable Wifi Off", "Phone", "No Sim", "Messenger", "Message", "Location On", "Location Off", "Live Help", "Invert Colors On", "Invert Colors Off", "Import Export", "Forum", "Email", "DND On", "Dialpad", "Dialer SIP", "Contacts", "Comment", "Clear All", "Chat", "Call Split", "Call Received", "Call Missed", "Call Merge", "Call Made", "Call End", "Call", "Business", "", "Stop", "Snooze", "Skip Prev", "Skip Next", "Shuffle", "Replay", "Repeat One", "Repeat", "Recent Actors", "Radio", "Queue Music", "Queue", "Playlist Add", "Play Shopping Baf", "Play Circle Outline", "Play Circle Fill", "Play Arrow", "Pause Circle Outline", "Pause Circle Fill", "Pause", "Not Interested", "New Releases", "My Library Music", "My Library Books", "My Library Add", "Movie", "Mic Off", "Mic None", "Mic", "Loop", "High Quality", "Hearing", "Games", "Fast Rewind", "Fast Forward", "Explicit", "Equalizer", "Closed Caption", "AV Timer", "Album", "Web", "Volume Up", "Volume Off", "Volume Mute", "Volume Down", "Video Cam Off", "Video Cam", "Video Collection", "Surround Sound", "Subtitles", "", "Warning", "Error", "", "Work", "Wallet Travel", "Wallet Membership", "Wallet Giftcard", "Visibility Off", "Visibility", "View Week", "View Stream", "View Quilt", "View Module", "View List", "View Headline", "View Day", "View Column", "View Carousel", "View Array", "View Agenda", "Verified User", "Turned in Not", "Turned In", "Trending Up", "Trending Neutral", "Trending Down", "Translate", "Track Changes", "Today", "TOC", "Thumbs Up Down", "Thumb Up", "Thumb Down", "Theaters", "Tab Unselected", "Tab", "System Update TV", "", "Swap Vert", "Swap Horiz", "Supervisor Account", "Subject", "Store", "Stars", "Star Rate", "Spell Check", "Speaker Notes", "Shopping Cart", "Shopping Basket", "Shop Two", "Shop", "Settings Voice", "Settings Remote", "Settings Power", "Settings Phone", "Settings Overscan", "Settings Input Svideo", "Settings Input HDMI", "Settings Input Composite", "Settings Input Component", "Settings Input Antenna", "Settings Ethernet", "Settings Display", "Settings Cell", "Settings Bluetooth", "Settings Backup Restore", "Settings Applications", "Settings", "Search", "", "Schedule", "Room", "Restore", "Report Problem", "Reorder", "Redeen", "Receipt", "History", "Question Answer", "Restore", "Print", "Polymer", "Picture in Picture", "Perm Scan Wifi", "Perm Phone Message", "Perm Media", "Perm Identity", "Perm Device Info", "Perm Data Setting", "Perm Contact Cal", "Perm Camera Mic", "Payment", "Page View", "Open With", "Open in New", "Open in Browser", "Note Add", "Mark Unread Inbox", "Loyalty", "Lock Outline", "Lock Open", "Lock", "List", "Launch", "Language", "Label Outline", "Label", "Invert Colors", "Input", "Info Outline", "Info", "HTTPS", "Home", "Highlight Remove", "Help", "Group Work", "Grade", "Get App", "Flip To Front", "Flip To Back", "Find Replace", "Find in Page", "Favorite Outline", "Favorite", "", "Face", "", "", "Extension", "Explore", "Exit to App", "Event", "Done All", "Done", "DNS", "Description", "Delete", "Dashboard", "Credit Card", "Class", "Check Circle", "Cached", "Bug Report", "Bookmark Outline", "Bookmark", "Book", "Backup", "Autorenew", "Assignment Turned In", "Assignment Returned", "Assignment Return", "Assignment Late", "Assignment Ind", "Assignment", "Assessment", "Aspect Ratio", "Announcement", "Android", "Alarm On", "Alarm Off", "Alarm Add", "Alarm", "Add Shopping Cart", "Account Circle", "Account Child", "", "Account Box", "Account Balance Wallet", "Accoutn Balance", "Accessibility", "3D Rotation"

NOTE: Be aware that the graphics in some stencils may not have been assigned names and so will only be identifiable by index.

Importing Graphics from Stencils

The importation of a graphic from a stencil into a document is a multi-step task perfect for simplifying through automation. Here are example routines for automating stencil import tasks.

usa-map

Although they are comprised of many graphics, some stencils, like the USA Map stencil, are often imported in their entirety. To accomplish the task of importing a multi-graphic stencil, a load() function is used to access the stencil file and then loop is used to import each of the stencil’s graphics. Because of the design of Omni Automation, the import process happens very quickly, and seems to be almost like a single import.

function importAllGraphicsFromNamedStencil(stencilName){ for(i = 0; i < app.stencils.length; i++){ stencil = app.stencils[i]; if (stencil.name.localeCompare(stencilName) == 0){ stencil.load(function(s){ console.log("Loaded stencil: “" + s.name + "”") document.windows[0].selection.canvas.duplicate(s.graphics) }) break } } }

If you have the USA Map stencil added to OmniGraffle, here’s how the previous function would be called to load the full stencil:

omnigraffle://localhost/omnijs-run?script=function%20importAllGraphicsFromNamedStencil%28stencilName%29%7B%0A%09for%28i%20%3D%200%3B%20i%20%3C%20app%2Estencils%2Elength%3B%20i%2B%2B%29%7B%0A%09%09let%20stencil%20%3D%20app%2Estencils%5Bi%5D%3B%0A%09%09if%20%28stencil%2Ename%2ElocaleCompare%28stencilName%29%20%3D%3D%200%29%7B%0A%09%09%09stencil%2Eload%28function%28s%29%7B%0A%09%09%09%09console%2Elog%28%22Loaded%20stencil%3A%20%E2%80%9C%22%20%2B%20s%2Ename%20%2B%20%22%E2%80%9D%22%29%0A%09%09%09%09document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%2Eduplicate%28s%2Egraphics%29%0A%09%09%09%7D%29%0A%09%09%09break%0A%09%09%7D%0A%09%7D%0A%7D%0AimportAllGraphicsFromNamedStencil%28%27USA%20Map%27%29

And here’s a function for importing a specific graphic from a stencil file. Once it has loaded the stencil, and located the graphic in the stencil, it uses the duplicate() method of the Canvas class to copy the graphic from the stencil into the current canvas.

function importNamedGraphicFromNamedStencil(graphicName, stencilName){ for(i = 0; i < app.stencils.length; i++) { let stencil = app.stencils[i]; if (stencil.name.localeCompare(stencilName) == 0) { stencil.load(function(s) { console.log("Loaded stencil: “" + s.name + "”") for(q = 0; q < s.graphics.length; q++){ aGraphicName = s.graphics[q].name if (aGraphicName != null){ if (aGraphicName.localeCompare(graphicName) == 0){ console.log("found graphic: “" + graphicName + "”") aStencilGraphic = s.graphics[q] cnvs = document.windows[0].selection.canvas rsltArray = cnvs.duplicate([aStencilGraphic]) aGraphic = rsltArray[0] aGraphic.geometry = new Rect(0, 0, aGraphic.geometry.width, aGraphic.geometry.height) document.windows[0].selection.view.select([aGraphic]) console.log("added graphic: “" + graphicName + "”") return aGraphic } } } throw new Error("Graphic “" + graphicName + "” is not in stencil “" + stencilName + "”") }) } } }

Using the previous function, here’s an example of how to import California from the USA Map stencil:

importNamedGraphicFromNamedStencil('CA', 'USA Map')
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