Site Tools


Adding Points at Curve Endpoints

Developer: RhinoScript
Summary: Demonstrates how to add point at the starting and ending locations of curves.

Question

I am looking for a script or help in writing a script that will place points on all the curve end points in a scene (i.e. 5,000 curves, 10,000 end points). Any ideas?

Answer

The following script should do the job:

RhinoScript

AddCurveEndPoints.rvb
Option Explicit
 
Sub AddCurveEndPoints()
  Const rhCurve = 4
 
  ' Get all the curve objects in the document
  Dim arrCurves
  arrCurves = Rhino.ObjectsByType(rhCurve)
  If IsNull(arrCurves) Then Exit Sub
 
  ' For better performance, turn off screen redrawing  
  Call Rhino.EnableRedraw(False)
 
  ' Process each curve       
  Dim strCurve
  For Each strCurve In arrCurves
    ' Add a point at the start of the curve
    Call Rhino.AddPoint(Rhino.CurveStartPoint(strCurve))
    ' If not closed, add a point at the end of the curve
    If Not Rhino.IsCurveClosed(strCurve) Then
      Call Rhino.AddPoint(Rhino.CurveEndPoint(strCurve))
    End If
  Next
 
  ' Turn screen redrawing back on  
  Call Rhino.EnableRedraw(True)
End Sub

Python

AddCurveEndPoints.py
import rhinoscriptsyntax as rs
 
def AddCurveEndPoints():
    # Get all the curve objects in the document
    curves = rs.ObjectsByType(rs.filter.curve)
    if not curves: return
 
    # For better performance, turn off screen redrawing
    rs.EnableRedraw(False)
 
    # Process each curve       
    for curve in curves:
        # Add a point at the start of the curve
        rs.AddPoint(rs.CurveStartPoint(curve))
        # If not closed, add a point at the end of the curve
        if not rs.IsCurveClosed(curve):
            rs.AddPoint(rs.CurveEndPoint(curve))
    # Turn screen redrawing back on  
    rs.EnableRedraw(True)
 
AddCurveEndPoints()




developer/scriptsamples/addcurveendpoints.txt ยท Last modified: 2015/09/14 (external edit)