# Python recursive script problem

**URL:** <https://discourse.mcneel.com/t/python-recursive-script-problem/161599>\
**Category:** Scripting\
**Tags:** windows, python, grasshopperrhino\
**Created:** [June 17, 2023, 12:52pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599 "2023-06-17T12:52:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 17, 2023, 12:52pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/1 "2023-06-17T12:52:26Z")

</div>

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…

```py
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)

```

 ![Substrate_Problem_02](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/1/5/715da0c2f5d178514d4a79e4058c86344d3f4c11.jpeg)

---

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 17, 2023, 1:03pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/2 "2023-06-17T13:03:26Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![11165](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11165/32/475956_2.png) [@11165](https://discourse.mcneel.com/u/11165)\
**Post date:** [June 17, 2023, 1:25pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/3 "2023-06-17T13:25:57Z")

</div>

What does “pt\_list” do?

---

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 17, 2023, 1:33pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/4 "2023-06-17T13:33:35Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![11165](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11165/32/475956_2.png) [@11165](https://discourse.mcneel.com/u/11165)\
**Post date:** [June 17, 2023, 1:40pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/5 "2023-06-17T13:40:25Z")

</div>

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

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/c/1/0c1a36f4362d561f9f479678f0dd46443e63f890.png)  
I tried to replicate your problem, without a file.

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

---

<div class="post-metadata">

**Author:** ![11165](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11165/32/475956_2.png) [@11165](https://discourse.mcneel.com/u/11165)\
**Post date:** [June 17, 2023, 2:12pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/6 "2023-06-17T14:12:24Z")

</div>

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/f/f/cff9edecae44b29e51baa87104cb71d2a0bff506.png)  
OK. I got it working and replicate your problem.

I will look into it

---

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 17, 2023, 2:12pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/7 "2023-06-17T14:12:47Z")

</div>

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](https://discourse.mcneel.com/uploads/short-url/nrUZArYoTR3BwABUPxXpyls2nd7.gh) (10.8 KB)

---

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 17, 2023, 2:14pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/8 "2023-06-17T14:14:21Z")

</div>

Thanks a lot for the effort Deer 11165 !!!

---

<div class="post-metadata">

**Author:** ![11165](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11165/32/475956_2.png) [@11165](https://discourse.mcneel.com/u/11165)\
**Post date:** [June 17, 2023, 2:28pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/9 "2023-06-17T14:28:07Z")

</div>

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/9/3/a9372dc0a384a779b4e6efb9bb879f1f63a0eb78.png)

[sub.gh](https://discourse.mcneel.com/uploads/short-url/7Km6V0IodYZABpf9C3Uhhptm1J3.gh) (5.2 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/2/6/f2683b43d56b687b2a398f0bfd97c769f793305e.png)

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.

---

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 17, 2023, 2:31pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/10 "2023-06-17T14:31:33Z")

</div>

Nice, good idea with the rebuild!

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

Thanks so much Deer

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [June 18, 2023, 4:11pm UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/11 "2023-06-18T16:11:30Z")

</div>

This old GHPython script might help as well:

> **[Window Frame Facade - random size surface division](https://www.grasshopper3d.com/forum/topics/window-frame-facade-random-size-surface-division?commentId=2985220%3AComment%3A1636837)**
>
> Good evening everybody.
> Is there anyway to do a facade like shown below. Dividing a surface into random rectangle shapes? There is this Launchbox tool for…

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/6/1/4618894f6cfa68449f311ccb2ea8fbe94ff7d074.png)

---

<div class="post-metadata">

**Author:** ![Zinssmeister](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/zinssmeister/32/681111_2.png) [@Zinssmeister](https://discourse.mcneel.com/u/Zinssmeister)\
**Post date:** [June 20, 2023, 7:24am UTC](https://discourse.mcneel.com/t/python-recursive-script-problem/161599/12 "2023-06-20T07:24:17Z")

</div>

Great, thanks! Will have a look into it…
