Let’s examine the Omni Automation and FileMaker scripts for transferring data to newly created shapes placed below the currently selected shapes in an OmniGraffle document. This design applies to both the Description and Summary scripts for creating new text containers.
Here is the code for the Omni Automation script for transferring data (the content of the Description or Summary fields) to a new shape. The placeholder for the passed data variables are colored like: DBTRANSFERDATA
2 Declare the offset (in points) of the new shape from the selected shape.
3 Declare the default font size for the text placed in the new shape.
5 Check to see if a single solid shape is selected in the document. If not, alert the user and stop.
10-30 Create a new shape based upon the size and position of the currently selected shape.
16 Set the text of the new shape using the text that replaced the placeholder DBTRANSFERDATA when the script was assembled and executed by the FileMaker database. In this example, the text will be either the contents of the Description or Summary fields of the current database record.
17 Set the name of the new shape using the text that replaced the placeholder DBIDFIELDVALUE when the script was assembled and executed by the FileMaker database. In this example, the name of the shape will be the value of SKU field of the current database record.
18-21 Set the value of the other metadata tags using the setUserData() method of the Graphic class.
22-30 Set the properties of the created shape and text.
In the example FileMaker database, the Omni Automation scripts to be executed are first assembled dynamically using FileMaker variables that replace placeholders in the encoded Omni Automation scripts, with encoded content from specific fields of the current record of the database.
Here is the FileMaker script for transferring text (in this case, the contents of the Description field) to a newly created shape in the OmniGraffle document:
1 The FileMaker script variable $dbName is created containing the URL encoded name of the database file.
2 The FileMaker script variable $identifierFieldName is created containing the URL encoded name of the field containing the unique identifier for the current record. In this case, the field name is: SKU
3 The FileMaker script variable $identifierFieldValue is created containing the URL encoded value of the field containing the unique identifier for the current record. In this case, the “SKU” field.
4 The FileMaker script variable $sourceFieldName is created containing the URL encoded name of the field containing the text to be transferred. In this case, the field name is: Description
5 The FileMaker script variable $productDescription is created containing the edited contents of the “Description” field, where the paragraph returns (¶) have been replaced with new-line indicators (\n).
6 The FileMaker script variable $encodedDescription is created containing the URL encoded contents of the $productDescription variable.
7 The FileMaker script variable $fontSize is created containing the value of the Export Type Size popup field.
8 The FileMaker script variable $omniscript is created containing the URL encoded Omni Automation script with its placeholders replaced by the corresponding FileMaker variables (see below)
9 The composite Omni Automation URL is launched, causing the Omni Automation script to be passed to OmniGraffle to be decoded and executed.
To insert the variables into the script, replacing the placeholders, the encoded Omni Automation script string is broken into sections (each string segment is closed with a beginning or ending quote mark) and the FileMaker variables are inserted between string segments between ampersand characters (&) that are used as concatenation operators.
Here’s a list of placeholders and their corresponding FileMaker variables:
EXPORTTEXTSIZE = $fontSize
DBTRANSFERDATA = $encodedDescription
DBFILENAME = $dbName
DBIDFIELDNAME = $identifierFieldName
DBIDFIELDVALUE = $identifierFieldValue
DBSOURCEFIELDNAME = $sourceFieldName
Add Text to Selected Shape
Here is the Omni Automation script for the FileMaker scripts that transfer field content into the currently selected solid graphic in the OmniGraffle document. Since no shape is created, this script is a simpler version of the previous script.
if (document.windows[0].selection.solids.length != 1){
title = "SELECTION ERROR"
message = "Please select a single solid graphic."
new Alert(title, message).show(function(result){})
} else {
aShape = document.windows[0].selection.solids[0]
aShape.text = 'DBTRANSFERDATA'
aShape.name = 'DBIDFIELDVALUE'
aShape.setUserData('DB-FILE-NAME','DBFILENAME')
aShape.setUserData('DB-ID-FIELD-NAME','DBIDFIELDNAME')
aShape.setUserData('DB-ID-FIELD-VALUE','DBIDFIELDVALUE')
aShape.setUserData('DB-SOURCE-FIELD-NAME','DBSOURCEFIELDNAME')
}
1 Check to see if a single solid shape is selected in the document. If not, alert the user and stop.
6 Identify the selected graphic.
7 Set the text contents of the selected graphic to the contents of either the description or summary record fields.
8 Set the name of the selected graphic to the value of the unique identifier record field. In this example, that is the SKU number.
9-12 Set the graphic’s metadata keys and values to those passed from the FileMaker database.
As with the previous script, this Omni Automation script is assembled dynamically with a FileMaker script that declares variables containing the record contents and then replaces placeholders in the encoded Omni Automation script with the contents of either the Description or Summary fields of the current database record.
1 The FileMaker script variable $dbName is created containing the URL encoded name of the database file.
2 The FileMaker script variable $identifierFieldName is created containing the URL encoded name of the field containing the unique identifier for the current record. In this case, the field name is: SKU
3 The FileMaker script variable $identifierFieldValue is created containing the URL encoded value of the field containing the unique identifier for the current record. In this case, the “SKU” field.
4 The FileMaker script variable $sourceFieldName is created containing the URL encoded name of the field containing the text to be transferred. In this case, the field name is: Description
5 The FileMaker script variable $productDescription is created containing the edited contents of the “Description” field, where the paragraph returns (¶) have been replaced with new-line indicators (\n).
6 The FileMaker script variable $encodedDescription is created containing the URL encoded contents of the $productDescription variable.
7 The FileMaker script variable $omniscript is created containing the URL encoded Omni Automation script with its placeholders replaced by the corresponding FileMaker variables (see below)
8 The composite Omni Automation URL is launched, causing the Omni Automation script to be passed to OmniGraffle to be decoded and executed.
To insert the variable, the encoded Omni Automation script string is broken into two sections (each string segment is closed with a beginning or ending quote mark) and the FileMaker variable is inserted between the string segments using ampersand (&) concatenation operators.
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.