Hi, I want to write a script in Python, but I can’t figure out how to fix this problem. Let’s say I have a list x
with different curve lengths and a list y
with values that I want to use to split list x
.
As you can see, the first curve is 4m long and was split into two 1m parts based on the values in
y
. The following y
value is 4, which is smaller than the remaining rest (2m) of the first curve, so the second curve of 10m would be considered and split into parts based on the y
values until the rest is smaller than the following y
value. All these split parts (including the rests) would be put into one output list. As you can see, I’ve attempted to write a script for this issue, but I can’t seem to figure it out. Any help or ideas would be greatly appreciated. Thank you in advance.import Rhino.Geometry as rg
def parse_length_list(length_string):
try:
# Convert the input string to a list of floats
return [float(val) for val in length_string.split(‘,’)]
except ValueError:
return None # Return None if there’s an issue with parsing
def split_curves(x_str, y_str):
x_lengths = parse_length_list(x_str)
y_lengths = parse_length_list(y_str)
if x_lengths is None or y_lengths is None:
return None # Return None if either x or y is not provided
result_curves = []
for x, y in zip(x_lengths, y_lengths):
remaining_length = x
while remaining_length > 0:
split_length = min(remaining_length, y)
line = rg.Line(rg.Point3d(0, 0, 0), rg.Point3d(split_length, 0, 0))
result_curves.append(line.ToNurbsCurve())
remaining_length -= split_length
return result_curves if result_curves else [rg.Line(rg.Point3d(0, 0, 0), rg.Point3d(0, 0, 0)).ToNurbsCurve()]
a = split_curves(x, y)
Grasshopper Script:
Problem.gh (9.1 KB)