Point on Curve, random

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


Hi @lbrooks, maybe below helps:

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
    # add points to document


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.

Thanks again!


Hi @lbrooks, rs.coerce… functions are not documented yet. Alternatively you can find a RhinoObject in the object table from an object id like this:

rh_obj = scriptcontext.doc.Objects.FindId(object_id)
if not rh_obj: 
    print "Object not found for id: {}".format(object_id)

The PointAtNormalizedLength is from from the RhinoCommon docs which you can find here.


Okay thanks :slight_smile: