TreeNode

According to Wikipedia a “tree” is a widely used abstract data type that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes. A TreeNode is one element in the chain of nodes that make up a tree.

Some of the terms used by both the TreeNode and Item classes incorporate terms that define hierarchical human relationships mixed with those terms defining the elements of actual trees. Here is a list of common terms used by both classes:

However, in terms of Omni Automation and OmniOutliner, a TreeNode represents a row in an OmniOutliner outline document. The following documentation describes the properties and functions of the TreeNode class.

TreeNode Properties

Here are the properties of an instance of the TreeNode class:

TreeNode Functions

Here are the methods used with an instance of the TreeNode class:

Here’s how to convert an item (row) reference into a node reference:

var row = rootItem.children[0] var editor = document.editors[0] var node = editor.nodeForObject(row)

Here are two scripts that use the rootNode property of the Editor class to expand or collapse the top-level items in an outline:

var editor = document.editors[0] editor.rootNode.children.forEach(function(node){ if(node.canExpand){node.expand()} })
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0Aeditor%2ErootNode%2Echildren%2EforEach%28function%28node%29%7B%0A%09if%28node%2EcanExpand%29%7Bnode%2Eexpand%28%29%7D%0A%7D%29
var editor = document.editors[0] editor.rootNode.children.forEach(function(node){ if(node.canCollapse){node.collapse()} })
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0Aeditor%2ErootNode%2Echildren%2EforEach%28function%28node%29%7B%0A%09if%28node%2EcanCollapse%29%7Bnode%2Ecollapse%28%29%7D%0A%7D%29

To completely expand the top-level items, including their children, pass a boolean value of true into the expand() function:

var editor = document.editors[0] editor.rootNode.children.forEach(function(node){ if(node.canExpand){node.expand(true)} })
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0Aeditor%2ErootNode%2Echildren%2EforEach%28function%28node%29%7B%0A%09if%28node%2EcanExpand%29%7Bnode%2Eexpand%28%29%7D%0A%7D%29
 

ItemTreeNode

An ItemTreeNode is an instance of the TreeNode class. The ItemTreeNode class is designed to serve as an mechanism for retrieving and setting the values for the state property and the contents of columns, providing parity with the functionality of the Item class.

Here are the properties of an instance of the ItemTreeNode class:

The properties of the State class are used as the value for the state property of the ItemTreeNode class:

var node = document.editors[0].selectedNodes[0] if(node.state === State.Checked){ var message = "Selected row status is checked." } else if (node.state === State.Mixed){ var message = "Selected row status is mixed." } else { var message = "Selected row status is unchecked." } new Alert('STATUS',message).show()
omnioutliner:///omnijs-run?script=node%20%3D%20document%2Eeditors%5B0%5D%2EselectedNodes%5B0%5D%0Aif%28node%2Estate%20%3D%3D%3D%20State%2EChecked%29%7B%0A%09message%20%3D%20%22Selected%20row%20status%20is%20checked%2E%22%0A%7D%20else%20if%20%28node%2Estate%20%3D%3D%3D%20State%2EMixed%29%7B%0A%09message%20%3D%20%22Selected%20row%20status%20is%20mixed%2E%22%0A%7D%20else%20%7B%0A%09message%20%3D%20%22Selected%20row%20status%20is%20unchecked%2E%22%0A%7D%0Anew%20Alert%28%27STATUS%27%2Cmessage%29%2Eshow%28function%28result%29%7B%7D%29

Here are the methods used with an instance of the ItemTreeNode class:

An example script using the Editor’s selection property to get the topic text of the first selected node:

var editor = document.editors[0] var topicColumn = document.outline.outlineColumn var node = editor.selection.nodes[0] if(node){ var topic = node.valueForColumn(topicColumn) var topicStr = (topic === null) ? '':topic.string console.log(topicStr) }
omnioutliner://localhost/omnijs-run?script=try%7Bvar%20editor%20%3D%20document%2Eeditors%5B0%5D%0Avar%20topicColumn%20%3D%20document%2Eoutline%2EoutlineColumn%0Avar%20node%20%3D%20editor%2Eselection%2Enodes%5B0%5D%0Aif%28node%29%7B%0A%09var%20topic%20%3D%20node%2EvalueForColumn%28topicColumn%29%0A%09var%20topicStr%20%3D%20%28topic%20%3D%3D%3D%20null%29%20%3F%20%27%27%3Atopic%2Estring%0A%09console%2Elog%28topicStr%29%0A%7D%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

An example script using the Editor’s selectedNodes property to get the topic text of the first selected node:

var editor = document.editors[0] var topicColumn = document.outline.outlineColumn var node = editor.selectedNodes[0] if(node){ var topic = node.valueForColumn(topicColumn) var topicStr = (topic === null) ? '':topic.string console.log(topicStr) }
omnioutliner://localhost/omnijs-run?script=try%7Bvar%20editor%20%3D%20document%2Eeditors%5B0%5D%0Avar%20topicColumn%20%3D%20document%2Eoutline%2EoutlineColumn%0Avar%20node%20%3D%20editor%2EselectedNodes%5B0%5D%0Aif%28node%29%7B%0A%09var%20topic%20%3D%20node%2EvalueForColumn%28topicColumn%29%0A%09var%20topicStr%20%3D%20%28topic%20%3D%3D%3D%20null%29%20%3F%20%27%27%3Atopic%2Estring%0A%09console%2Elog%28topicStr%29%0A%7D%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

An example script for appending to the note of the first selected node:

var editor = document.editors[0] var notesColumn = document.outline.noteColumn var node = editor.selection.nodes[0] if(node){ var note = node.valueForColumn(notesColumn) if (note === null){ var newNote = "How now brown cow." } else { var newNote = note.string + " " + "How now brown cow." } node.setValueForColumn(newNote, notesColumn) }
omnioutliner://localhost/omnijs-run?script=try%7Bvar%20editor%20%3D%20document%2Eeditors%5B0%5D%0Avar%20notesColumn%20%3D%20document%2Eoutline%2EnoteColumn%0Avar%20node%20%3D%20editor%2Eselection%2Enodes%5B0%5D%0Aif%28node%29%7B%0A%09var%20note%20%3D%20node%2EvalueForColumn%28notesColumn%29%0A%09if%20%28note%20%3D%3D%3D%20null%29%7B%0A%09%09newNote%20%3D%20%22How%20now%20brown%20cow%2E%22%0A%09%7D%20else%20%7B%0A%09%09newNote%20%3D%20note%2Estring%20%2B%20%22%20%22%20%2B%20%22How%20now%20brown%20cow%2E%22%0A%09%7D%0A%09node%2EsetValueForColumn%28newNote%2C%20notesColumn%29%0A%7D%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%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