DataTree<T>

References
public class DataTree<T> : IGH_DataTree
Implements basic Grasshopper Data Tree functionality in an easy-to-use class. This class is used primarily in Scripting components. If you're using the Grasshopper SDK you should consider using the GH_Structure<T> class instead.
TData type of this class.

Constructors

DataTree

#
Default constructor, create an empty data tree.
public DataTree()

DataTree

#
Create a true duplicate of another data tree.
public DataTree(
DataTree<T>
other,
Tree to duplicate
copyDelegate
Delegate function used to duplicate individual items.
)

DataTree

#
Create a shallow duplicate of another data tree. This means it will create a new tree that contains the same items.
public DataTree(
DataTree<T>
other
Tree to duplicate
)

DataTree

#
Create a tree with a single branch
public DataTree(
data,
Data to append to the tree.
root = null
Branch path of first branch. If Null, the default path is used.
)

Properties

BranchCount

#
Gets the number of branches defined in this tree.
public int BranchCount { get; }

Branches

#
Gets a list of all the data-arrays in this tree
public IList<List<T>> Branches { get; }

DataCount

#
Gets the total number of data items (including nulls) stored in all branches.
public int DataCount { get; }

Paths

#
Gets a list of all the branch paths in this tree.
public IList<GH_Path> Paths { get; }

TopologyDescription

#
Gets a description of the topology of the tree. Useful for debugging purposes.
public string TopologyDescription { get; }

Indexers

Item

#
Gets or set the data item at the specified path and index.
public T this[
path,
Path of the data branch to retrieve. Path must be defined in the tree.
index
Index of item to retrieve. Index must be defined in the branch.
] { get; set; }
NullReferenceExceptionThrown if the path doesn't exist.
IndexOutOfRangeExceptionThrown if the index does not exist within the path list.

Methods

Add

#
Add (append) a data item to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
public void Add(
T
data,
Data to append.
path
Branch path to append to.
)

Add

#
Add (append) a data item to the last branch in the tree. If no branches exist yet, a new one will be created with [path = {0}]
public void Add(
T
data
Data to append.
)

AddRange

#
Add (append) a list of data items to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
public void AddRange(
data,
Data to append.
path
Data path.
)

AddRange

#
Add (append) a list of data items to the last branch in the tree. If no branch exists yet, a new one will be created.
public void AddRange(
data
Data to append
)

AllData

#
Collects all data in the tree in a single list. Does not alter the topology of this tree.
public List<T> AllData()
A linear list containing all data items in all branches.

Branch

#
Gets the list of data which belongs to a given Branch path.
public List<T> Branch(
path
Data path to retrieve.
)

Branch

#
Gets the list of data which belongs to the branch path at the given index.
public List<T> Branch(
index
Index of data to retrieve.
)
IndexOutOfRangeExceptionThrown if the index does not represent a valid path.

Branch

#
Gets the list of data which belongs to a given Branch path.
public List<T> Branch(
params int[]
path
Data path to retrieve.
)

Clear

#
Clears the entire tree.
public void Clear()

ClearData

#
Removes all data from all branches without affecting the tree topology.
public void ClearData()

EnsurePath

#
Create a new branch with the specified path if it doesn't already exists.
public List<T> EnsurePath(
path
Path of the branch to ensure.
)
The list that belongs to the specified path.

EnsurePath

#
Create a new branch with the specified path if it doesn't already exists.
public List<T> EnsurePath(
params int[]
path
Path of the branch to ensure.
)
The list that belongs to the specified path.

Flatten

#
Flattens the entire tree into a single path.
public void Flatten(
flatten_path = null
The path of the flattened data. If null, the path will be {0}
)

Graft

#
Graft all paths in this tree. "Grafting" means appending a new branch for every item in an existing branch.
public void Graft(
skip_nulls = false
If true, null items in the grafted path will not be included in the new tree.
)

Graft

#
Graft a single path in the tree. "Grafting" means appending a new branch for every item in an existing branch.
public void Graft(
path,
Path to graft.
skip_nulls = false
If true, null items in the grafted path will not be included in the new tree.
)

Insert

#
Insert a data item to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
public void Insert(
T
data,
Data to insert.
path,
Branch path to insert into.
index
Insertion index.
)

ItemExists

#
Test if the specified path + item index are defined inside the tree.
public bool ItemExists(
path,
Path to test for.
index
Item index to test.
)
True if the specified path exists and contains the specified index.

MergeStructure

#
Merge a Grasshopper parameter structure into this DataTree. Expert user function. If you don't know what a GH_Structure(Of T) is you don't have to worry about this method.
public void MergeStructure(
structure,
Parameter data structure to merge.
hint
Type hint converter to use during merging.
)
Remarks: Expert user function, don't go near GH_Structures if you're not intimately familiar with the Grasshopper SDK.

MergeTree

#
Merges two trees together. Data inside similar branches will be merged into single lists and unique paths will be appended. The other tree will not be altered, so beware that data is now shared among both trees.
public void MergeTree(
other
Tree to merge with.
)
ArgumentNullExceptionThrown if other is a null reference.

MergeWithParameter

#
Utility function for assigning Script Data Trees to output parameters. Expert user function, don't worry your pretty little head about this one.
public bool MergeWithParameter(
param
Parameter to merge with.
)
True on success, false on failure.
MergeWithParameter

Path

#
Gets the data path at the specified index.
public GH_Path Path(
index
Index of path to retrieve.
)
IndexOutOfRangeExceptionThrown if the index does not represent a valid path.

PathExists

#
Test if the specified path is already defined inside the tree.
public bool PathExists(
path
The branch path to search for
)
True if the path already exists, false if it doesn't.

PathExists

#
Test if the specified path is already defined inside the tree.
public bool PathExists(
params int[]
path
The branch path to search for.
)
True if the path already exists, false if it doesn't.

RemovePath

#
Removes a path and all associated data from the structure. If the path doesn't exist, nothing will happen.
public void RemovePath(
path
Path to remove.
)

RemovePath

#
Removes a path and all associated data from the structure. If the path doesn't exist, nothing will happen.
public void RemovePath(
params int[]
path
Path to remove.
)

RenumberPaths

#
Renumber all paths in this data tree, using a single incrementing path index.
public void RenumberPaths()

RenumberPaths

#
Renumber all paths in this data tree, using a single incrementing path index.
public void RenumberPaths(
mask
String formatting mask for paths. Use semi-colons for path index separators and "{i}" as a path index placeholder. Examples:

"{i}" -> {i}

"0;{i}" -> {0;i}

"{i};0;0" -> {i;0;0}

)

SimplifyPaths

#
Simplify the branches in this tree by removing all identical path entries. The length of the shortest path will be indicative of the similarity search depth. If this tree only contains a single branch, the branch wil be simplified to its last index.
public void SimplifyPaths()

ToString

#
Creates a brief description of the tree.
public override string ToString()
A String representing the current state of the data tree.
Object.ToString

TrimExcess

#
Trims the excess allocated memory in all branches
public void TrimExcess()