Rhino.Python Scripting: Automatic selection of certain curves

I have a model in which out of numerous amounts of curves in the work space, I only want four. So i have curve 1 and cyrve 2 on mesh A, and curve 3 and curve 4 on mesh B. I will do meshintersect+splitmeshwithcurve+deletemeshface, hope that makes sense. Now i am working on a script in which rhino can detect curve 1 and 2 are on mesh A, and perform the intersection etc and this continues on with mesh B.
I originally secluded them by length but each model has different lengths and even range varies, so its not repeatable. SO for now i have settled on selecting these four curves out of the work space using get object and then performing the necessary tasks. BUT of course this is not preferred. Someone gave me advice on using coordinates ( creating bboxes round each curve, finding the centroid and then using either the x y or z coordinates to select the curves) but thats a bit of work for me, although im still looking into it. But for now this get object script i have keeps crashing Rhino, it works at times, and crashes most of the time. can someone check what exactly is wrong with it?

from Rhino.Commands import Result
from Rhino.DocObjects import ObjectType
import rhinoscriptsyntax as rs
from scriptcontext import doc

bfcrv_id = rs.GetObjects(“Select bf curves”,4)
if bfcrv_id:
#create an empty list
for obj in bfcrv_id:
#find curves among the objects
if abs(rs.CurveLength(obj)<100):
#curve meets selection criteria, append to the list

ffcrv_id = rs.GetObjects(“Select ff curves”,4)
if ffcrv_id:
#create an empty list
for obj in ffcrv_id:
#find curves among the objects
if abs(rs.CurveLength(obj)<100):
#curve meets selection criteria, append to the list



back_objs=rs.ObjectsByLayer(“3.08 Back Face Surface”)
if back_objs:
for obj in back_objs:
if rs.IsMesh(obj):
if abs(rs.MeshQuadCount(obj)>=target):

#get a list of all objects on the layer you want
front_objs=rs.ObjectsByLayer(“3.07 Front Face Surface”)
if front_objs:
for obj in front_objs:
if rs.IsMesh(obj):
if abs(rs.MeshQuadCount(obj)>target):

Split mesh with curve

rs.Command("-_SplitMeshWithCurve selid “+str(braces[0])+” selid “+str(bfcurve[0]))
rs.Command(”-_SplitMeshWithCurve selid “+str(braces[0])+” selid “+str(bfcurve[1]))
rs.Command(”-_SplitMeshWithCurve selid “+str(faces[0])+” selid “+str(ffcurve[0]))
rs.Command(”-_SplitMeshWithCurve selid “+str(faces[0])+” selid "+str(ffcurve[1]))

delete smaller meshes


if layer4_objs:
for obj in layer4_objs:
if rs.IsMesh(obj):
if abs(rs.MeshQuadCount(obj)<sm):


Hello - I think you could start by making a custom filter for curves < 100 units long along the lines of


import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

def IsCurveShortEnoughGeometryFilter (rhObject, geometry, componentIndex):
    c = rs.coercecurve(geometry)
    if c:
        if c.GetLength() < 100: return True
    return False

def RunCommand():
    tol =sc.doc.ModelAbsoluteTolerance
    id =  rs.GetObject("Select a curve shorter than 100", rs.filter.curve, False, False, IsCurveShortEnoughGeometryFilter)
    if not id: return
    meshIds = rs.ObjectsByType(32)
    if not meshIds:
        print "No meshes found"
    crv = sc.doc.Objects.Find(id).Geometry
    pt = crv.PointAtStart
    ID = None
    meshes = [sc.doc.Objects.Find(meshId).Geometry for meshId in meshIds]
    for n in range(len(meshes)):
        x = meshes[n].ClosestPoint(pt)
        cp = meshes[n].ClosestPoint(pt)

        if pt.DistanceTo(cp) < tol:
            ID = meshIds[n]
    if ID: rs.SelectObject(ID)

if __name__=="__main__":

Depending on just what you have you could also check with say Mesh.ClosestPoint(), or compare bounding boxes or some other way to determine which curve is on which mesh.

Shifting this to the Scripting forum…


1 Like