McNeel Wiki
Calculating the Lengths of Curves
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
DeveloperRhinoScript
SummaryDemonstrates 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
  )
rename · changes · history · subscriptions · lost and found · references · file upload