I am trying to generate some shapes, and I am stuck with the rs.GetPointOnCurve function. I’d like to randomly generate a set of points that are on a curve, but I can’t figure out how to automatically create the points, instead of manually selecting them.
Thank you for your help! Code below:
import rhinoscriptsyntax as rs
centerCircle = rs.AddEllipse(rs.WorldXYPlane(),10 ,10.0)
points = []
for p in range (10):
point = rs.GetPointOnCurve(centerCircle, "Point on curve")
rs.AddPoint(point)
points.append(point)
print(points)
import Rhino
import rhinoscriptsyntax as rs
import random
def DoSomething():
crv_id = rs.GetObject("Select a curve", rs.filter.curve, True, False)
if not crv_id: return
curve = rs.coercecurve(crv_id, -1, True)
points = []
for x in xrange(100):
# get a random number between 0 and 1
t = random.random()
# get random point on curve
p = curve.PointAtNormalizedLength(t)
# store point in list
points.append(p)
# add points to document
rs.AddPoints(points)
DoSomething()
Thank you so much! This does exactly what I am looking for.
Where can I find these methods (rs.coercecurve and PointAtNormalizedLength) in the documentation? So far I’ve been using the reference here: https://developer.rhino3d.com/api/RhinoScriptSyntax/ but they don’t come up in a search.
I am actually preparing to teach a short course on python scripting with Rhino, so I’m hoping to point students toward the documentation for each of my examples.