Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:straightencircles [2015/09/14] (current)
Line 1: Line 1:
 +====== Straightening Circles ======
 +====== RhinoScript ======
 +> **Version:​** //Rhino 4.0//
 +> **Summary:​** //​Demonstrates how to create lines based on circle geometry using [[developer:​rhinoscript|RhinoScript]].//​
 +
 +=====Question=====
 +Can Rhino turn circles into straight lines?
 +
 +=====Answer=====
 +Consider the following subroutine:
 +
 +
 +<code vb>
 + '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 + '​ StraightenCircles.rvb -- September 2008
 + '​ If this code works, it was written by Dale Fugier.
 + '​ If not, I don't know who wrote it.
 + '​ Works with Rhino 4.0.
 +
 + ​Option Explicit
 +
 + '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 + '​ StraightenCircles
 + '​ Creates lines based on the circumferences of circles.
 + '​ Lines will be oriented based on the plane of the circle.
 +
 + Sub StraightenCircles
 +
 +   Dim obj_list, obj 
 +   Dim length, plane, origin, xaxis
 +   Dim endpt, line
 +
 +   ​obj_list = Rhino.GetObjects("​Select circles to straighten",​ 4, True, True)
 +   If IsArray(obj_list) Then
 +
 +     Call Rhino.EnableRedraw(False)
 +
 +     For Each obj In obj_list
 +       If Rhino.IsCircle(obj) Then
 +         '​ Gather data
 +         ​length = Rhino.CurveLength(obj)
 +         plane = Rhino.CurvePlane(obj)
 +         ​origin = plane(0)
 +         xaxis = plane(1)
 +         '​ Calculate
 +         xaxis = Rhino.VectorUnitize(xaxis)
 +         xaxis = Rhino.VectorScale(xaxis,​ length)
 +         endpt = Rhino.PointAdd(origin,​ xaxis)
 +         line = Rhino.AddLine(origin,​ endpt)
 +         Call Rhino.SelectObject(line)
 +       End If
 +
 +     Next
 +
 +     Call Rhino.EnableRedraw(True)
 +
 +   End If
 +
 + End Sub
 +
 + '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 +
 + ​Rhino.AddStartupScript Rhino.LastLoadedScriptFile
 + ​Rhino.AddAlias "​StraightenCircles",​ "​_NoEcho _-RunScript (StraightenCircles)"​
 +
 +</​code>​
 +
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/straightencircles.txt ยท Last modified: 2015/09/14 (external edit)