Site Tools


Calculating the Lengths of Curves

Developer: 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.

 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

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.

 _-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
 )


developer/scriptsamples/curvelength.txt ยท Last modified: 2011/11/11 by dale