Python recursive script problem

Hi friends,

after a long time I am trying to get back into Rhino / Python. Are there any good recommended tutorials, I am struggling mostly with all the different Classes and Geometry Types in Rhino / Grasshopper / Python.

Here is a learning script with a problem, Iam trying to make a recursive “Substrate” style algorithm, simular to the build in one from Grasshopper. I got it going somehow, struggled with “rs.SpiltCurve”, had to use “rs.Coercecurve” and “rg.Interval” to reparametrize the domain and get it going.

Somehow some of my new lines get scaled (not the same length anymore as before) in the next iteration. Not every line, not in every iteration. I got no clue whats happening. Any Ideas? Sorry for this noob questions…

import rhinoscriptsyntax as rs
import  Rhino.Geometry as rg
import random

def substrate_line(curve_list):
    rnd_sel = random.randrange(len(curve_list))
    crv = rs.coercecurve(curve_list[rnd_sel],1)
    crv.Domain = rg.Interval(0.0, 1.0)
    rnd_pos = random.uniform(0.40, 0.6)
    crv_pt = rs.EvaluateCurve(crv, rnd_pos )
    crv_tan = rs.CurveTangent (crv, rnd_pos )
    tan_pt = crv_pt + rs.VectorRotate(crv_tan, 90.0, [0,0,1])  
    my_line = rs.AddLine(crv_pt,tan_pt)
    rs.ExtendCurve( my_line, 0, 1, curve_list )    
    split_crvs = rs.SplitCurve(crv, rnd_pos, delete_input=False)  
    del curve_list[rnd_sel]
    curve_list.extend(( split_crvs[0], split_crvs[1], my_line ))
    pt_list.append(crv_pt)
    return curve_list

# input
curve_list = rs.ExplodeCurves(rectangle_curve) 
pt_list = []
random.seed(seed)

# function
for i in range(count):
    result = substrate_line(curve_list)

I should have mentioned, that I startet with a curve list, took a random curve, made a perpenticular curve to it (my_line) and extended it to one of the rest lines in curve_list. Then splited the selected curve, deleted the old one from the list and extended the list with fresh new splitted lines. Hope this makes sense…

What does “pt_list” do?

Sorry, I should have deleted that, “pt_list” was just for work in progress, to show me the splitting and “my_line” start location. No real use…

At lease please upload your file. to save other’s time. hahaha


I tried to replicate your problem, without a file.

Why am I doing this while you are the one asking for help?


OK. I got it working and replicate your problem.

I will look into it

Sorry, had to leave my desk shortly. My mistake, I concentrated so hard on putting correct python code into a forum post, I forgot to attach the file

substrate_01.gh (10.8 KB)

Thanks a lot for the effort Deer 11165 !!!

sub.gh (5.2 KB)

I added a rebuild and in this way all curve extended would have 2 control points instead of 3 (because of the extend).
I am not quit sure it solve the problem, you can try that more times.

personally I recommend using Rhinocommon instead of rhinoscript.

1 Like

Nice, good idea with the rebuild!

Yes, I guess thats my main problem, I am mixing RhinoScript and RhinoCommon.

Thanks so much Deer

1 Like

This old GHPython script might help as well:

1 Like

Great, thanks! Will have a look into it…