top of page

Range Rebuild Curves

Writer's picture: David MansDavid Mans

💻 Rhino 5

🔼 Rhino Script

🛠️ Visual Basic

 

Developed for optimizing curves for laser cutting files, this script allows the user to rebuild curves that fall within a certain point count range. The user is asked to select a series of curves and is then prompted to select a minimum and maximum point count as well as a point count for rebuilding if the curve falls within these parameters. Additionally, the ability to override the degree of curvature is included, if the value is zero the existing curvature is retained.

 
Option Explicit
'Script written by <David Mans>
'Script copyrighted by <Neoarchaic Studio>
'Script version Tuesday, June 09, 2009 3:07:42 PM
  
Call Main()
Sub Main()
    Dim curves, arrValue
  
    curves = Rhino.GetObjects("Select Curves to Rebuild", 4,, True)
    If isNull(curves) Then Exit Sub
  
    arrValue = Rhino.PropertyListBox(array("Range Minimum", "Range Maximum", "Point Count", "Degree (0=current)"), array(2, 10, 5, 0))
    If isNull(arrValue) Then Exit Sub
    Call Rhino.EnableRedraw(False)
    Call reBuildRange(curves, CInt(arrValue(0)), CInt(arrValue(1)), CInt(arrValue(2)), CInt(arrValue(3)))
    Call Rhino.EnableRedraw(True)
  
End Sub
Function reBuildRange(arrCurves, minVal, maxVal, dblValue, dblDegree)
    reBuildRange = Null
    Dim i, tVal, tDeg
    Dim arrOutput()
    ReDim arrOutput(uBound(arrCurves))
  
    For i = 0 To uBound(arrCurves) Step 1
        'find the existing point count, set rebuild to false
        tVal = Rhino.CurvePointCount(arrCurves(i))
        'if the point count is in range then set rebuild to true and specify new point count
        If tVal >= minVal And tVal <= maxVal Then
            'if degree is set to zero use existing curve degree, otherwise specify new curve degree
            If dblDegree <= 0 Then
                tDeg = Rhino.CurveDegree(arrCurves(i))
            Else
                tDeg = dblDegree
            End If
            arrOutput(i) = Rhino.RebuildCurve(arrCurves(i), tDeg, dblValue)
        Else
            arrOutput(i) = arrCurves(i)
        End If
    Next
  
    reBuildRange = arrOutput
End Function
 


1 view

Recent Posts

See All
bottom of page