No, it returns an array of indices for each needle point, which means a list of indices for each point that you search from (cf. reference), a list of lists so to speak.
But you’re right the indices indeed point to points from the original point cloud.
You should be able to simply loop over the returned array and get individual items/indices by using two array operators (i.e. my_array)
Thanks for getting back to me so quickly! That’s what I was expecting too.
Below is a simplification of what I was trying to do, but it just returns
Runtime error (TypeErrorException): ‘d__5[Point3d]’ object is not subscriptable
from Rhino.Geometry import Point3d, PointCloud
from Rhino.Collections.RhinoList import PointCloudKNeighbors
ptcloud = PointCloud()
for i in range(7):
for j in range(7):
for k in range(7):
ptcloud.Add(Point3d(k, j, i))
reference_pts = 
for i in range(3):
reference_pts.append(Point3d(i+2, 4, 4))
ptc_index = PointCloudKNeighbors(ptcloud, reference_pts, 2)
Rather than getting an array, I seem to be getting a:
<Rhino.Collections.RhinoList+<KNeighbors>d__5'1[[Rhino.Geometry.Point3d, RhinoCommon, Version=7.0.20252.11325, Culture=neutral, PublicKeyToken=552281e97c755530]] object at 0x0000000000000089 [Rhino.Collections.RhinoList+<KNeighbors>d__5'1[Rhino.Geometry.Point3d]]>
I’m definitely doing something wrong, but I can’t figure out what it is.
NARUTO-sama’s code already seems quite concise. It takes him exactly two lines (i.e. 13-14) to do what you asked for. The rest is just constructing the point cloud and reference points list.
If you want to get the neighboring points quickly with a one liner - continuing NARUTO-sama’s code on line 18 -, you can do this:
# Get the neighboring points per reference point in a nested list (or list of lists)
nested_npts = [[ptcloud.PointAt(i) for i in ref_ipt] for ref_ipt in ptc_index ]
# Get all the neighboring points in a flat, one-dimensional list
flat_npts = [ptcloud.PointAt(i) for ref_ipt in ptc_index for i in ref_ipt]
You could even wrap these lines, including NARUTO-sama’s, into a function that returns the points in whatever data structure you prefer.