Exporting Text

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 

// default settings var defaultOffset = 12 var defaultTextSize = EXPORTTEXTSIZE 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 { cnvs = document.windows[0].selection.canvas solid = document.windows[0].selection.solids[0] // duplicate rectangle shape offset below selected shape cRect = solid.geometry nRect = new Rect(cRect.minX, cRect.maxY + defaultOffset, cRect.width, cRect.height) aShape = cnvs.addShape('Rectangle',nRect) 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') aShape.shadowColor = null aShape.strokeType = null aShape.fillType = null aShape.autosizing = TextAutosizing.Overflow aShape.textHorizontalAlignment = HorizontalTextAlignment.Left aShape.textHorizontalPadding = 0 aShape.textVerticalPlacement = VerticalTextPlacement.Top aShape.textVerticalPadding = 0 aShape.textSize = defaultTextSize }
omnigraffle://localhost/omnijs-run?script=%2F%2F%20default%20settings%0Avar%20defaultOffset%20%3D%2012%0Avar%20defaultTextSize%20%3D%20EXPORTTEXTSIZE%0A%0Aif%20%28document%2Ewindows%5B0%5D%2Eselection%2Esolids%2Elength%20%21%3D%201%29%7B%0A%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09message%20%3D%20%22Please%20select%20a%20single%20solid%20graphic%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09solid%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Esolids%5B0%5D%0A%09%2F%2F%20duplicate%20rectangle%20shape%20offset%20below%20selected%20shape%0A%09cRect%20%3D%20solid%2Egeometry%0A%09nRect%20%3D%20new%20Rect%28cRect%2EminX%2C%20cRect%2EmaxY%20%2B%20defaultOffset%2C%20cRect%2Ewidth%2C%20cRect%2Eheight%29%0A%09aShape%20%3D%20cnvs%2EaddShape%28%27Rectangle%27%2CnRect%29%0A%09aShape%2Etext%20%3D%20%27DBTRANSFERDATA%27%0A%09aShape%2Ename%20%3D%20%27DBIDFIELDVALUE%27%0A%09aShape%2EsetUserData%28%27DB-FILE-NAME%27%2C%27DBFILENAME%27%29%0A%09aShape%2EsetUserData%28%27DB-ID-FIELD-NAME%27%2C%27DBIDFIELDNAME%27%29%0A%09aShape%2EsetUserData%28%27DB-ID-FIELD-VALUE%27%2C%27DBIDFIELDVALUE%27%29%0A%09aShape%2EsetUserData%28%27DB-SOURCE-FIELD-NAME%27%2C%27DBSOURCEFIELDNAME%27%29%0A%09aShape%2EshadowColor%20%3D%20null%0A%09aShape%2EstrokeType%20%3D%20null%0A%09aShape%2EfillType%20%3D%20null%0A%09aShape%2Eautosizing%20%3D%20TextAutosizing%2EOverflow%0A%09aShape%2EtextHorizontalAlignment%20%3D%20HorizontalTextAlignment%2ELeft%0A%09aShape%2EtextHorizontalPadding%20%3D%200%0A%09aShape%2EtextVerticalPlacement%20%3D%20VerticalTextPlacement%2ETop%0A%09aShape%2EtextVerticalPadding%20%3D%200%0A%09aShape%2EtextSize%20%3D%20defaultTextSize%0A%7D

 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:

fm-script=text-into-clone

 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:

fm-script-text-into-clone

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') }
omnigraffle://localhost/omnijs-run?script=if%20%28document%2Ewindows%5B0%5D%2Eselection%2Esolids%2Elength%20%21%3D%201%29%7B%0A%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09message%20%3D%20%22Please%20select%20a%20single%20solid%20graphic%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09graphic%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Esolids%5B0%5D%0A%09graphic%2Etext%20%3D%20%27XXXXX%27%0A%7D

 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.

fm-script-text-into-shape

 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.

fm-script-omniscript-text-in-shape
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