Python won't let me extract a centroid from a polyline object

Hi All,

I’m running into an issue with a Python script, in which I have a Rhino PolylineCurve object and I need to extract the centroid of that object. When I print the object in the Python window, I get this text:

<Rhino.Geometry.PolylineCurve object at 0x000000000001C835 [Rhino.Geometry.PolylineCurve]>

the object is called by the variable ‘zone_crv’

Now I run this command on the object:
zone_cp = rh.AreaMassProperties.Centroid(zone_crv)

…and I get this error:
Runtime error (ArgumentTypeException): getset_descriptor is not callable

What am I missing here? Seems I need to convert this object to something else that’s callable, but I can’t find anything online about this issue or how to solve it.

Thanks in advance!

cb

A polyline has neither area nor volume. Would it suffice to take the average of the polyline segments’ endpoints? Or their midpoints?

Thanks for the quick response. It’s a closed polyline, so I’m hoping to recreate the ‘AreaCentroid’ command in Rhino, which works with closed polylines; is there a different / equivalent command I should be using?

I can definitely take the average of the polyline points (and maybe that’s what the AreaCentroid command already does?), but I was hoping for a simpler solution.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_AreaMassProperties_Compute_2.htm

Should be the same in python. You can run the static compute method with a curve to return the AreaMassProperties, but the curve must be planar (as well as closed).

1 Like

Great, that works well; thanks so much!

1 Like

A simple approach is to get the underlying Polyline and its center point:

test,pl = plc.TryGetPolyline()
if test:
    pt = pl.CenterPoint()
2 Likes