List_to_tree or Tree_to_list

Hi guys,

CurveClosestPoint

Parameters

curve_id (guid): identifier of a curve object
point (point): sampling point

the CurveClosestPoint method takes only one point

import rhinoscriptsyntax as rs
from ghpythonlib import treehelpers as ght
y = [(20,-10,0), (50,-10,0), (80,-10,0)]
a = rs.CurveClosestPoint(x, ght.list_to_tree(y))

(sorry for stupid question):
using list_to_tree or tree_to_list, it is not possible to have the same result as the selected def?

ps in Python but without using for loops

You can do this, but out of the box, there is not function in rhinoscriptsyntax that you can pass a list or or data tree of points to:

import rhinoscriptsyntax as rs
from ghpythonlib import treehelpers

points = [(20,-10,0), (50,-10,0), (80,-10,0)]
params = [rs.CurveClosestPoint(curve, pt) for pt in points]

The list comprehension will populate a list with closest point parameters for each point in points, but it uses a for each loop.

thanks @diff-arch great alternative, I like :+1:

so if I understand correctly there is no way to use List_to_tree or Tree_to_list in Py?

ps but one question: for sure it’s the way i used it that is wrong, but if they exist List_to_tree or Tree_to_list in Py means they can be used or wrong?

No, no, these functions are explicitly for use in GHPython, but they are mostly for converting input trees to nested lists and/or nested lists to output data trees.
If you want to call a certain function, you just need to provide it the expected data type. You can’t pass it a data tree, if the function requires a single point, like in your example above.

:+1: