9.6. Accessing tree nodes

In TrEd macros as well as in TrEd itself tree nodes are represented by FSNode objects. They are basically only references to hash tables where the attribute-name/attribute-value information is stored as a key/value pair. Moreover, the FSNode object provide a few methods to access the node's neighbors in the tree.

The macro invoked by user action (e.g. pressing the keyboard shortcut assigned to the macro) may use the following global variables (declared within the TredMacro namespace, but exported by default to other derived contexts) to refer to the active node and to the root of the active tree (how to access any tree in the file will be told later):

$this

Points to the active node in the current tree. Macros may use this variable to access the active node as well as to make other node active (by assigning a different node reference to it).

$root

Points to the root of the current tree. Macros may use this variable to access the root of the tree and (consequently) to access the whole tree. However, all assignments to this variable are ignored by TrEd.

9.6.1. Accessing node attributes

If $node is a FSNode object reference, the value of the attribute attr is returned by the $node->{attr} expression. To give the node's attr attribute new value, say val, the following simple assignment may be used:

$node->{attr}='val';