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 (document.windows[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()') scriptURL.call(function(reply){ solid = document.windows[0].selection.solids[0] solid.text = decodeURIComponent(reply) solid.textSize = 36 solid.textHorizontalAlignment = HorizontalTextAlignment.Left }) }
omnigraffle:///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%20shape%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09function%20rootDescendentsText%28%29%7B%0A%09%09textBlock%20%3D%20%22%22%0A%09%09rootItem%2Edescendents%2EforEach%28function%28item%29%7B%0A%09%09%09textBlock%20%3D%20textBlock%20%2B%20%22%5Ct%22%2Erepeat%28item%2Elevel-1%29%20%2B%20item%2Etopic%20%2B%20%22%5Cn%22%0A%09%09%7D%29%0A%09%09return%20encodeURIComponent%28textBlock%29%0A%09%7D%0A%09var%20scriptURL%20%3D%20URL%2EtellScript%28%22omnioutliner%22%2C%20rootDescendentsText%2EtoString%28%29%20%2B%20%27%5Cn%27%20%2B%20%27rootDescendentsText%28%29%27%29%0A%09scriptURL%2Ecall%28function%28reply%29%7B%0A%09%09solid%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Esolids%5B0%5D%0A%09%09solid%2Etext%20%3D%20decodeURIComponent%28reply%29%0A%09%09solid%2EtextSize%20%3D%2036%0A%09%09solid%2EtextHorizontalAlignment%20%3D%20HorizontalTextAlignment%2ELeft%0A%09%7D%29%0A%7D
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