解决 GHPython 使用 ghpythonlib.components 作为函数时无法输出 Tree 的问题

这是给用户做支持时遇到的一个问题,分享给小伙伴

假如说一个 Component 输出的是 TreeData,然后将其作为函数来使用的时候,通过下面的方式是无法获得 Tree 的,而得到的只是一个 LIst:

import ghpythonlib.components as ghcomp

groups, indices= ghcomp.PointGroups(points = pts, distance = tol)

在 GHPython 中,同通过下面的方式可以解决这个问题:

import Rhino.NodeInCode as node

comp = node.Components.FindComponent("PointGroups")

groups,indices = comp.InvokeKeepTree(pts,tol)

通过 NodeInCode 可以解决这个问题,因为 ghpythonlib.components 用的只是 Invoke 方法,而不是 InvokeKeepTree 方法。

2 个赞

补充一种方法:
用ghpythonlib.components也可以实现tree输出。不过需要在调用电池前先调用tree.

import ghpythonlib.components as ghcomp

groups, indices= ghcomp.trees.PointGroups(points = pts, distance = tol)

3 个赞