List of a List retrieving GhPython


I have exploded a brep, taken the faces that I need and trying to get the centroid. In the first iteration it works like charm, but the second time I call the def, the values of the list are preserved. So I tried to use my counter as the index that I wish to retrieve. It leads to getting just one coordinate of both iterations instead of getting the desired list of the list (see images attached). Any ideas?

Thank you in advance.

Print print0

How are you defining the list? Can you share some more of your code to show where you are getting the problem?
You should avoid defining a list as a default argument in a function as it is only defined once and then reused on subsequent calls - is that the issue?
Also be careful when copying a list as you can get unexpected behaviour:

Thank you for your answer Graham.

The list is being defined as shown. I use the SurfaceAreaCentroid on a surface and I choose the first output (which is the desired point) and I put it in the list. The fact that the list is defined only once is not a problem (I think) as long as I am able to retrieve the desired item of the list. The index of this item is the same as a counter I am using. Although, when I try to retrieve the first item of the list (as shown in the screenshots) I get just the x-coordinates.

In other words the expected result is [x0,y0,z0] but i get [x0,x1]. It seems that it is not actually a list but some kind of a matrix that i have and I am calling the first column instead of the first row. Or maybe it is some kind of a branch structure.

Anyhow, if reply sounds gibergaber I could share the code. :slight_smile:

In that case I think you need to share what you are doing with the ‘iterations’ as the output looks normal to me - in your second example you are accessing the x value by taking index [0] from the centroid point.
In your first example above you seem to be correctly printing the centroid point of two different faces, presumably on two iterations? :
x, y, z:
-0.0238, 0.7355, 0
-0.0238, 6.51, 0

Ok, then it’s me that thinks wrong. For me (novice I have to admit) the normal to get when printing centroid4[0] would be the coordinates of the first point. So I guess the question is how can I get the coordinates of the first point?
x, y, z:
-0.0238, 0.7355, 0


can you post a file with the appropriate input geometry? (if the geometry is from the rhino document, either internalize the geometry in the gh file or post the accompanying rhino file.)