How do I extract points from this list?



I have a list that was the result of solving CurveBrep intersection, the list looks like this:

[Array[Point3d], Array[Point3d], Array[Point3d], Array[Point3d]((<Rhino.Geometry.Point3d object at 0x000000000000EC1D [-23.8044134556235,8,8.92537370705992]>)), Array[Point3d]((<Rhino.Geometry.Point3d object at 0x000000000000EC1E [-23.8044134556235,8,8.92537370705992]>, <Rhino.Geometry.Point3d object at 0x000000000000EC1F [-31,2.2566892228611,11.3210518241447]>))]

Some lines didn’t intersect with the Brep, therefore, some items in the list don’t have a point, some lines intersected twice or more, therefore, some items in the list contain one or more points

The question is how do I correctly tell python to check if the list item has a point, I need to extract the points from that list.

I tried this to iterate through the list items:

for i in list:
    if i.startswith('Array[Point3d]((<Rhino.Geometry'):

Obviously, this didn’t work. How should I approach this?




Without the example file, i can only asume this pseudocode works:

new_list = []

# iterate over the nested list 
for arr in nested_list:
    # use array if it is not empty
    if arr.Count != 0:
        # convert array to list and extend new_list
        new_list.extend( [arr] )
return new_list

Btw. never use the word list as a variable name…

(qythium) #4

At the risk of explaining the obvious, your method didn’t work because the items of your list are Array[Point3d] 's , and not strings. What you are seeing from the print output is their representational form, or the output of the python repr() function. ( You can’t ask someone ‘Do you start with “Bob”?’ when you mean to ask about their name, for example)

Since you’re just trying to extract all the points, you could do this:

from operator import add
new_list = reduce(add, nested_list)

which concatenates the inner arrays using the + operator into a single array. Empty arrays are automatically ignored because adding them doesn’t produce any change.