DataTree<T>
ReferencesImplements 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.
Type parameters:
| T | Data type of this class. |
Constructors
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
Indexers
Item
#Gets or set the data item at the specified path and index.
Exceptions:
| NullReferenceException | Thrown if the path doesn't exist. |
| IndexOutOfRangeException | Thrown 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.
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.
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.
AllData
#Collects all data in the tree in a single list. Does not alter the topology of this tree.
Returns: A linear list containing all data items in all branches.
Branch
#Gets the list of data which belongs to a given Branch path.
Branch
#Gets the list of data which belongs to the branch path at the given index.
Exceptions:
| IndexOutOfRangeException | Thrown if the index does not represent a valid path. |
Branch
#Gets the list of data which belongs to a given Branch path.
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.
Returns: The list that belongs to the specified path.
EnsurePath
#Create a new branch with the specified path if it doesn't already exists.
Returns: The list that belongs to the specified path.
Graft
#Graft all paths in this tree. "Grafting" means appending a new branch for every item in an existing branch.
public void Graft()
Graft
#Graft a single path in the tree. "Grafting" means appending a new branch for every item in an existing branch.
Insert
#Insert a data item to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
ItemExists
#Test if the specified path + item index are defined inside the tree.
Returns: 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.
Exceptions:
| ArgumentNullException | Thrown 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.
Returns: True on success, false on failure.
Implements: MergeWithParameter
Path
#Gets the data path at the specified index.
Exceptions:
| IndexOutOfRangeException | Thrown if the index does not represent a valid path. |
PathExists
#Test if the specified path is already defined inside the tree.
Returns: True if the path already exists, false if it doesn't.
PathExists
#Test if the specified path is already defined inside the tree.
Returns: 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.
RemovePath
#Removes a path and all associated data from the structure. If the path doesn't exist, nothing will happen.
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.
Returns: A String representing the current state of the data tree.
Overrides: Object.ToString