Canvas Metadata

One of the great power-user features of OmniGraffle is the ability to assign metadata to objects. Assigned metadata can then be retrieved and used in automating the construction and formatting of documents. Very powerful indeed!

This webpage describes the various canvas metadata properties and methods that are available for your use in creating automated publishing tools.

Metadata Properties

Every canvas has two basic metadata properties: id and name. The id and name properties can be used to identify a canvas.

function canvasWithID(canvasID){ for(i = 0; i < canvases.length; i++){ if (canvases[i].id === canvasID){ return canvases[i] } } errorString = "There is no canvas with id: " + canvasID.toString() new Alert('ERROR', errorString).show(function(result){}) throw new Error(errorString) } canvasWithID(1)
function canvasWithName(canvasName){ for(i = 0; i < canvases.length; i++){ if (canvases[i].name.localeCompare(canvasName) == 0){ return canvases[i] } } errorString = "There is no canvas named: " + canvasName new Alert('ERROR', errorString).show(function(result){}) throw new Error(errorString) } canvasWithName('iPad Horizontal')

Notes and User-Data Keys

The Canvas class does not directly support the notes and userData properties used by graphics to store and retrieve data. However, the value of the canvas background property is a Solid Graphic that inherits the metadata properties and methods of a Graphic.

document.windows[0].selection.canvas.background

Since it is a Graphic, the background shape of every canvas supports the two basic Graphic metadata properties: notes and userData.

The notes property can store a description or other textual data related to the canvas.

cnvsBackground = document.windows[0].selection.canvas.background cnvsBackground.notes = 'How Now Brown Cow'
omnigraffle:///omnijs-run?script=cnvsBackground%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%2Ebackground%0AcnvsBackground%2Enotes%20%3D%20%27How%20Now%20Brown%20Cow%27

The metadata properties of a canvas can be viewed and edited within the Canvas tab of the information sidebar on both macOS (left) and iOS (right).

canvas-notes

User-Data Keys are one or more user-defined pairs of key names and data values that are assigned to a graphic object. A key could be any type of identifier, such as a SKU or product number, or a person’s name. The key value can be any type of data expressed as a string.

Graphic Metadata Methods

Here are Graphic instance methods for getting and setting user data keys and values:

A function for setting user data:

function setCanvasUserDataForKey(key,value){ graphic = document.windows[0].selection.canvas.background graphic.setUserData(key,value) } setCanvasUserDataForKey('SKU','W123456789')
omnigraffle:///omnijs-run?script=function%20setCanvasUserDataForKey%28key%2Cvalue%29%7B%09%09%0A%09graphic%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%2Ebackground%0A%09graphic%2EsetUserData%28key%2Cvalue%29%0A%7D%0AsetCanvasUserDataForKey%28%27SKU%27%2C%27W123456789%27%29

A function for getting user data. The result will be 'undefined' if no matching key is found:

function getCanvasUserDataForKey(key){ graphic = document.windows[0].selection.canvas.background return graphic.userData[key] } getCanvasUserDataForKey('SKU')
canvas-notes
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