Grasshopper: Map a path using C#

The Path Mapper is a component that allows you to map data to different branches. It is also possible to replicate this behaviour entirely in C#.

The following code maps object x to path address 0, 0, 5. See this post for a simple overview on data trees in Grasshopper.

‘DataTree’ is the class made specifically for the C# component to handle data trees. (If you’re programming in Visual Studio, it’s better to use GH_Structure.) We use a different class, GH_Path, as the tool to define the path structure.

C# code

  private void RunScript(object x, object y, ref object A)
  {

    int[] address = {0, 0, 5};
    var pth = new GH_Path(address);
    var tree = new DataTree<object>();

    tree.Add(x, pth);
    A = tree;

  }