Points not recognized as points after converting to nested list

Been struggling with this for a few times, when I convert points into python, the constant error is that it tells me a float object has no DistanceTo.

The steps I’ve tried:

  • Set to tree access
  • Set to Point3d

Been doing the above to no avail and I’ve done this for years but suddenly it’s misbehaving. Anyone can help? :frowning:
glitchy points.gh (9.8 KB)

Pnts is a regular list, you can just give it list access.

I’m not sure what you’re trying to do, but I think you unintentionally are looping through the coordinates of each point with the second for loop (the one with index of j). I think you meant to loop through all the points except PointColle[i], but instead you looped through the x,y,z coordinates of PointColle[i].

Also you never append anything to Sampled.

glitchy points2.gh (19.0 KB)

hi yes that’s a truncated bit that i can’t figure out. not sure why but it keeps looping thru the point coordinates (i don’t want this, i never had it before?) but i want to iterate thru points in sub lists.

tldr right now i have a code that has initial point group, i would like to take this set of points, find the next closest set, find next closest…I’m unable to make it array according to curve, because I want this logic to apply across multiple “ribs” that are twisting and turning. I’m rusty, help!

…not sure why but it keeps looping thru the point coordinates…

It’s the second index which you indicate with the variable j. A point is actually a list of 3 values [x, y, z]. So, if you have a point P, P[0] references x and P[1] references y and P[2] references z.

In your case PointColle[i] is referencing a point and so PointColle[i][j] would reference one of its coordinates.

If you are going through a list of objects, you can only use a single index to reference any object in that list. If you add a second index, the second index necessarily references a list contained by the object that was referenced by the first index. Since the object is a point and it is itself a list of coordinates, the second index will be assumed to be referencing those coordinates.

It’s sounds confusing but I can’t think of a better way to say it.

As far as looping through the coordinates, line 15 should be changed to…


However I have rewritten the entire thing based on what I think you are trying to do. So, here’s a rhino file and a grasshopper file. I’m not exactly sure what you wanted to do, but it looks like you are trying to sort the points by distance. So, that’s what this script does. The slider will make a little sphere over the selected point. The lower the value on the slider, the closer the point is to the start poitn. The greater the value, the further the point.

I did not include the start point in the list of sorted points, but that could easily be done.

Also, the sorted points will not include any points that coincide with the start point (that is, points that have a distance of 0 from the start point are excluded). But this could also be changed.

There’s probably a better way to do this, but this is what I came up with.

point_test.3dm (51.6 KB)

[edited to say I have improved this code in the next comment]
glitchy points fixed1.gh (10.4 KB)

This is an improved version using zip and sorted much like you did in your code. I used a dictionary in my previous version and that might cause some issues for points that have the same coordinates.

Also, this version is commented to show my code logic more clearly.

You can exclude the StartPt from the final SortedPts list by uncommenting the last line.
glitchy points fixed2.gh (11.5 KB)

Edited to add another improvement…in this one, you can exclude the start point via a toggle component.
glitchy points fixed3.gh (14.7 KB)

1 Like

hello! sorry for the late reply, i was trying to understand this and do more work on the code. this was a miracle solver, thank you! can i just ask though, how does this not require a “treehelper” in front of the list to make it work? was there something in python3 that was changed that i didn’t know of? thank you so much again!

1 Like

Hi @al.

No problem. I’m glad it was helpful.

how does this not require a “treehelper” in front of the list to make it work

In the case of the grasshopper script you first shared, the Pts variable was not a tree (which I understand to be a list of lists). It was just a normal list, so the treehelper was not needed. But, depending on how you collect the points for the Pts variable in the actual grasshopper file (not the simplified one you shared with us), it could indeed be a tree. I think you can guarantee a list by setting the input variable to “Flatten” (just right-click on the Pts variable and choose Flatten)