Import from OmniOutliner

In this section, the text of an outline in OmniOutliner can be retrieved and imported into the selected text box in an OmniGraffle document. The example begins with a look at two OmniOutliner functions for retrieving text from the current outline document.

Text of the Top-Level Entries of an Outline

The following function can be used to combine the text from the top-level outline items into a paragraph-delimited block of text.

function rootChildrenText(){ topics = new Array() rootItem.children.forEach(function(item){ topics.push(item.topic) }) return topics.join('\n') }

Tab-Indented Text of the full Outline

This OmniOutliner function will retrieve the text of the outline with tab indents to indicate the hierarchy of the outline elements.

function textOfFullOutline(){ textBlock = "" rootItem.descendents.forEach(function(item){ textBlock = textBlock + "\t".repeat(item.level-1) + item.topic + "\n" }) return textBlock }

Call and Response

Depending upon the desired results, either of the functions above can be used in a Call and Response scenario to extract and place data from the outline into a text box selected in an OmniGraffle document.

The calling function is declared in the script (lines 6 - 12), and is then converted into an OmniJS script URL (line 13), which is then called (line 14), and the results (reply) of the calling script is processed within the callback handler (lines 15 - 17).

NOTE: be sure to encode the text returned from the initial function (line 11), and decode the text in the main script (line 16)

if ([0].selection.solids.length != 1){ title = "SELECTION ERROR" message = "Please select a single shape." new Alert(title, message).show(function(result){}) } else { function rootDescendentsText(){ textBlock = "" rootItem.descendents.forEach(function(item){ textBlock = textBlock + "\t".repeat(item.level-1) + item.topic + "\n" }) return encodeURIComponent(textBlock) } var scriptURL = URL.tellScript("omnioutliner", rootDescendentsText.toString() + '\n' + 'rootDescendentsText()'){ solid =[0].selection.solids[0] solid.text = decodeURIComponent(reply) solid.textSize = 36 solid.textHorizontalAlignment = HorizontalTextAlignment.Left }) }

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.