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!
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)
left_branch_vec.Rotate(
-spread + random.uniform(0, vspread),
normal_plane.XAxis
)
left_branch_vec *= shrink + random.uniform(0, vshrink)
get_branch_rec(
end, left_branch_vec, spread, vspread, shrink, vshrink, depth - 1
)
right_branch_vec = rg.Vector3d(vec)
right_branch_vec.Rotate(
spread + random.uniform(0, vspread),
normal_plane.XAxis
)
right_branch_vec *= shrink + random.uniform(0, vshrink)
get_branch_rec(
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 = []
get_branch_rec(
iRootPosition, iRootDirection,
iSpreadAngle, iSpreadVariation, iShrink, iShrinkVariation,
10
)
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. https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CreatePipe_1.htm
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
continue
# .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
pipes.extend(breps)
# Outputs
a = branches
b = pipes