Rs Create Center Point
Last changed: dale@mcneel.com-204.177.179.144

.
DeveloperRhinoScript
SummaryDemonstrates how to mark the center points of closed planar curves with a point object.

Question

I have a pattern of circles from which I need to extract their center points. Is there a command or script that I can use to do this?

Answer

Yes. See the following RhinoScript code.

  Sub MarkCenterPoints()
    Dim curves, crv, pt, arr
    curves = Rhino.GetObjects("Select closed planar curves", 4, ,True)
    If IsArray(curves) Then
      Rhino.EnableRedraw False
      For Each crv In curves
        pt = vbNull
        If Rhino.IsCircle(crv) Then
          pt = Rhino.CircleCenterPoint(crv)
        Else
          arr = Rhino.CurveAreaCentroid(crv)
          If IsArray(arr) Then pt = arr(0)
        End If
        If IsArray(pt) Then
          Rhino.SelectObject Rhino.AddPoint(pt)
        End If
      Next        
      Rhino.EnableRedraw True
    End If
  End Sub

Here is a button macro version of the above script:

  ! _-Runscript (
  curves = Rhino.GetObjects("Select closed planar curves", 4, ,True)
  If IsArray(curves) Then
  Rhino.EnableRedraw False
  For Each crv In curves
  pt = vbNull
  If Rhino.IsCircle(crv) Then
  pt = Rhino.CircleCenterPoint(crv)
  Else
  arr = Rhino.CurveAreaCentroid(crv)
  If IsArray(arr) Then pt = arr(0)
  End If
  If IsArray(pt) Then
  Rhino.SelectObject Rhino.AddPoint(pt)
  End If
  Next        
  Rhino.EnableRedraw True
  End If
  )