Using data trees with ghpythonlib.components

I am trying to use ghpythonlib.components with a data tree, but always getting flattened lists as a result. I have tried to follow this example but ghpythonlib.tree.function() returns that tree is not part of ghpythonlib. In the example below I want to order find the closest point from multiple curves for a grafted list of points. The following does not work;

import ghpythonlib.components as ghcomp
import ghpythonlib.treehelpers as th
#pts = a list of points
#crvs = a list of two or more crvs
closest_pts = ghcomp.CurveClosestPoint(th.list_to_tree([[p] for p in pts]),crvs)[2])
sorted_pts = ghcomp.SortList(closest_pts)[0]
closest_pt = ghcomp.ListItem(sorted_pts, 0, False)

Also how can this example be made to leverage ghpythonlib.parallel ?
Can parallel computation be harnessed within the script when it runs only once as a component but has a host of parallel enabled functions within it? or does ghpythonlib.parallel require the component to run multiple times in order to take effect?

1 Like

you may have to upload your .gh file
what’s the error message?
there is also no ghcomp.Sort() method

It should have been SortList() (updated)
I simplified the issue because this is a part of a much larger example, and my issue is generic; How to pass data that is not flat to a ghcomp.function() and return a non-flattened result (preserving the datatree structure) (3.5 KB)

I can’t reproduce your problem. It seems to work just fine here. Tree structure preserved.

1 Like (4.9 KB)

This works well, however my issue is how to achieve this behavior when the tree structure is generated inside the script, so the component does not execute multiple times (it executes only once).

I edited the example to illustrate the issue.

I see your point. Not sure why. I’m curious too. @piac @DavidRutten @scottd
Perhaps something to do with GH_Structure rather than DataTree?