rs.GetRectangle problem

Hi,

I run he script below and pick the points in the order mentioned in the rhino file attached.
The rectangle gets printed, but when i try to run something on it like areacentroid i get “Parameter must be a Guid or string representing a Guid”. And this is because points 2 and 3 are too close to each other.

Why is this happening? how can i avoid it?

190920 getrectangle.3dm (76.5 KB) 190920 getrectangle.py (187 Bytes)

import rhinoscriptsyntax as rs

rectangle = rs.GetRectangle (mode=2, base_point=None, prompt1=None, prompt2=None, prompt3=None)

print rectangle
print rs.CurveAreaCentroid(rectangle)

Hi,

what rs.GetRectangle returns is a .Net array of points and not a reference to a Curve object in the document. Yet that is what rs.CurveAreaCentroidis expecting.
What you can do is create a polyline from the points and get he AreaCentroid from that:

import rhinoscriptsyntax as rs
import Rhino
rectangle = rs.GetRectangle (mode=2, base_point=None, prompt1=None, prompt2=None, prompt3=None)

#make the Array a list
rect_points = list(rectangle)
#add first point as last point to get a cloded polyline
rect_points.append(rect_points[0])
#add polyine to document
polyline_id = rs.AddPolyline(rect_points)
#compute
c_point, c_vec =  rs.CurveAreaCentroid(polyline_id)
#add point
rs.AddPoint(c_point)
#dispode of polyline
rs.DeleteObject(polyline_id)

#Note that you can also use geometry for calculations without adding it to the document:
polyline = Rhino.Geometry.PolylineCurve(rect_points)
c_point, c_vec =  rs.CurveAreaCentroid(polyline)
#add a circle to differentiate between the point above
rs.AddCircle(c_point, 1)
#no need to delete the polyline as it is not added to the document

Does this make sense?
-Willem