grasshopper 构造 DataTree 树形数据以及Graft Flatten Simplify的理解

问题的来源:

要在grasshopper里面输出 类似于二维数组的数据

但是在 grasshopper里的 C# 电池里面,无法显示 二维ArrayList里面的数据。

 

 

在 C# 电池里参考这个帖子:

https://discourse.mcneel.com/t/create-data-tree-with-c/68944/2

   C#电池codes如下: 
  // object 可以替换成其他的数据格式,也可以不换 输入端口 type 可能需要改
    Grasshopper.DataTree<object> tree = new Grasshopper.DataTree<object>();

    // 建立个list
    System.Collections.Generic.List<object> subtree = new System.Collections.Generic.List<object>();

    // 添加数据
    subtree.Add(10);
    subtree.Add(78);
    subtree.Add(56);

    GH_Path subPath = new GH_Path(124);

    tree.AddRange(subtree, subPath);

    A = tree;

 或者更简单一点:

    // 建立list  C# 版本
    System.Collections.Generic.List<object> subtree = new System.Collections.Generic.List<object>();

    // 添加数据
    subtree.Add(10);
    subtree.Add(78);
    subtree.Add(56);

    // 采用默认的序列
    result = subtree;

# python 版本
# python 版本
import rhinoscriptsyntax as rs
from Grasshopper.Kernel.Data  import GH_Path
from Grasshopper import DataTree

layerTree = DataTree[object]()

path = GH_Path(555)
layerTree.Add(2323, path)
layerTree.Add(564, path)


path2 = GH_Path(34)
layerTree.Add(1, path2)
layerTree.Add(5, path2)


a = layerTree

 

import rhinoscriptsyntax as rs
from Grasshopper.Kernel.Data  import GH_Path
from Grasshopper import DataTree

layerTree = DataTree[object]()

# 可以增加多个子branch 结构
path = GH_Path(555, 77) # 或者通过引用一个已经存在GH_Path的方式,即{555:77},也可以代替:path = GH_Path(otherExistPathType)
layerTree.Add(2323, path)
layerTree.Add(2323, path)
layerTree.Add(564, path)
layerTree.Add(564, path) 


path2 = GH_Path(34, 10)
layerTree.Add(1, path2)
layerTree.Add(5, path2)
layerTree.Add(5, path2)
layerTree.Add(5, path2)


a = layerTree

 

 

 如果要读取datatree

 

Path 要转换成list之后方便提取里面的branch层级,否则容易溢出

这里有类似的定义:

http://james-ramsden.com/data-trees-and-c-in-grasshopper/

DataTree, GH_Structure, IGH_Structure 三者之间的关系:

 

 具体可参见官方文档:

https://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_Kernel_Data_GH_Structure_1.htm

https://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_DataTree_1.htm#!

到此为止,可以引出 grasshopper 树形数据的处理 以及 list 和 tree:

 

在 Param Viewer中, 我们看到只有一个分支包含48个元素的一个列表。将所有数据放到  {0}  的路径下。

 

在 Param Viewer中 , 所有的数据有8个分支,每个分支有6个原子,每个原子含有一个元素。

 

在 Param Viewer 中, 仍然有8个分支,每个分支有6个原子,但是第一个分支已经去掉了。

 

Path mapper  

路径映射,对路径进行编辑修改 ,可以针对自己想要的结果,自定义。

 

一些经常用到的快捷键:

双击输入 scribble就行 输入注释;

选择多个电池 ,右击 选择组;

point list 画出点对象的默认 index;

 

参考资料:

grasshopper 官方文件

链接:https://pan.baidu.com/s/1LhvslLPdcs1zKxtj5NxJfw
提取码:e9y0
复制这段内容后打开百度网盘手机App,操作更方便哦

https://modelab.gitbooks.io/grasshopper-primer/1-foundations/1-5/3_creating-data-trees.html

https://developer.rhino3d.com/api/grasshopper/html/d823ee90-ea94-4a8a-a972-df5d006a8d9f.htm

https://www.youtube.com/watch?v=9TvVahUs3cQ

http://jinjieming.com/grasshopper%E6%A0%91%E5%BD%A2%E6%95%B0%E6%8D%AE%E7%9A%84%E9%80%89%E5%8F%96/

 

posted @ 2020-05-19 16:50  谦曰盛  阅读(6093)  评论(0编辑  收藏  举报