Problem with "Numbers to Points" in GH python

Hello everyone. I’m faced with the problem
that i cannot apply appropriate mask for the
point=gh.NumberstoPoints(pointlist,???)

Just XYZ didn’t work.

Trying to investigate that i found:

How you can see, X input of GH Python script node
print output is a certain <type ‘CoordinateMask’>
If we trying run it through the panel node it converts to
<type ‘str’>

Here is the description of NumberstoPoints function in
help tab of script editor window:

Help on function NumberstoPoints in module ghpythonlib.components:
| NumberstoPoints(*args, **kwargs) |
| Convert a list of numbers to a list of points
| Input:
| numbers [Number] - Numbers to merge into points
| mask [Coordinate Mask] - Mask for coordinate composition
| Returns: [Point] - Ordered list of points

Now I’ve found a workaround - I’m adding

point=gh.NumberstoPoints(pointlist,1)[0]

in code and it works for one point, but i want to know
the “official” way to set the appropriate mask for that
function while grasshopper scripting.

Some years ago on Grasshopper3D forum
@DavidRutten write back on similar question,
but it works for node programming, not for python script.

‌The AddPoint function from rhinoscriptsyntax can directly take a list as an argument.

rs.AddPoint([x, y, z])

You can use a list it with the Rhino.Geometry.Point3d by unpacking the list with an asterisk.

foo = [x, y, z]
rg.Point3d(*foo)

NtoP.gh (12.1 KB)

It looks like an workaround likewise, how do you think?

If you need to convert a list with three numbers into a point, what I’ve shown is the most straight forward method.
What’s the goal of using coordinate mask? Do you want to change the coordinates order?

import Rhino.Geometry as rg

coords = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
table = {'X': 0, 'Y': 1, 'Z': 2}

order = [table[item] for item in str(mask)]

a = []
for coord in coords:
    pt = rg.Point3d.Origin
    for idx, coord_idx in enumerate(order):
        pt[idx] = coord[coord_idx]
    a.append(pt)


NtoP.gh (7.9 KB)

1 Like

The goal is to gain new knowledge on how to use a coordinate mask inside a python script without input nodes and “bypass crutches”

1 Like