How to create pipe using grasshopper python(tree growth truck thickness)

Hi all,

I am trying to add thickness to the tree growth script i just developed, however I cannot figure out how to create a thickness(pipe) around the lines I created, I tried with the Rhino.Geometry.Brep.CreatePipe, but its not working. Can someone help me looking at the script?? Thank you very much!

tree growth adding (6.8 KB)

Hi @mengxihex,

import Rhino.Geometry as rg
import scriptcontext as sc
import random

# Set the document tolerances as global constants 
MTOL = sc.doc.ModelAbsoluteTolerance
ATOL = sc.doc.ModelAngleToleranceRadians

# random.seed(10)  # optional random seed

def get_branch_rec(start, vec, spread, vspread, shrink, vshrink, depth):
    # dir() is reserved in python and should not overwritten
    end = start + vec
    branches.append(rg.Line(start, end))

    if (depth > 0):
        normal_plane = rg.Plane(end, vec)

        left_branch_vec = rg.Vector3d(vec)
            -spread + random.uniform(0, vspread), 
        left_branch_vec *= shrink + random.uniform(0, vshrink)
            end, left_branch_vec, spread, vspread, shrink, vshrink, depth - 1

        right_branch_vec = rg.Vector3d(vec)
            spread + random.uniform(0, vspread), 
        right_branch_vec *= shrink + random.uniform(0, vshrink)

            end, right_branch_vec, spread, vspread, shrink, vshrink, depth - 1

## -----------------------------------------------------------------------------

# No need to initialise these above the function because it is called below
branches = []
pipes = []

    iRootPosition, iRootDirection, 
    iSpreadAngle, iSpreadVariation, iShrink, iShrinkVariation,  

for i in range(len(branches)):
    curve = rg.LineCurve(branches[i])  # no need to convert to Nurbs curve
    # Rhino.Geometry.Brep.CreatePipe returns an array of breps not a single one
    # cf.
    breps = list(rg.Brep.CreatePipe(curve, 0.1, True, 0, False, MTOL, ATOL))
    if len(breps) < 1:  # check if no breps were created
        print "Failed to pipe branch at index,", i
    # .extend adds items from one list to the end of another list
    # .append adds the list of items to the end of another list, thus creating a list of lists

# Outputs
a = branches
b = pipes
1 Like

Thank you so much for your help! merry Christmas!

1 Like

You’re welcome. Happy holidays! :christmas_tree: