Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:curvelength [2015/09/14] (current)
Line 1: Line 1:
 +====== Calculating the Lengths of Curves ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to calculate the lengths of curve objects using RhinoScript.//​
 +
 +=====Question=====
 +Is there a command to output a list of lengths for a selected series of curves? The **Length** command gives a composite length and the list command does not give the curve lengths as far as I understand.
 +
 +=====Answer=====
 +The following RhinoScript code demonstrates how to do the above.
 +
 +<code vb>
 + ​Option Explicit
 +
 + Sub CurveLength ()
 +   Dim arrCurves, dblTotal, dblLength, i
 +   ​dblTotal = 0.0
 +   ​arrCurves = Rhino.GetObjects("​Select curves for length calculation",​ 4, True, True)
 +   If IsArray(arrCurves) Then
 +     For i = 0 To UBound(arrCurves)
 +       ​dblLength = Rhino.CurveLength(arrCurves(i))
 +       ​Rhino.Print("​Curve"​ & CStr(i) & " = " & CStr(dblLength))
 +       ​dblTotal = dblTotal + dblLength
 +     Next
 +     ​Rhino.Print "Total length: " & " = " & CStr(dblTotal)
 +   End If
 + End Sub
 +
 +</​code>​
 +Here is the toolbar button macro version. Just create a new toolbar button and paste the following code into either the left or right mouse button command window.
 +
 +<code vb>
 + ​_-NoEcho
 + ​_-RunScript (
 + ​arrCurves = Rhino.GetObjects("​Select curves for length calculation",​ 4, True, True)
 + If IsArray(arrCurves) Then
 + ​dblTotal = 0.0
 + For i = 0 To UBound(arrCurves)
 + ​dblLength = Rhino.CurveLength(arrCurves(i))
 + ​Rhino.Print("​Curve"​ & CStr(i) & " = " & CStr(dblLength))
 + ​dblTotal = dblTotal + dblLength
 + Next
 + ​Rhino.Print "Total length: " & " = " & CStr(dblTotal)
 + End If
 + )
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/curvelength.txt ยท Last modified: 2015/09/14 (external edit)