Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:createcenterpoint [2015/09/14] (current)
Line 1: Line 1:
 +====== Marking Center Points of Closed Curves ======
 +> **Developer:​** [[developer:​rhinoscript|RhinoScript]]
 +> **Summary:​** //​Demonstrates 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.
 +
 +<code vb>
 + 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
 +</​code>​
 +Here is a button macro version of the above script:
 +
 +<code vb>
 + ! _-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
 + ​) ​
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/createcenterpoint.txt ยท Last modified: 2015/09/14 (external edit)