i am using this script to divide line to several points but get error when i try to compile.
import Rhino.Geometry as rg
import ghpythonlib.treehelpers as th
def divide_curve(curve, num_segments):
if not curve or num_segments <= 0:
return None # Ensure valid input
total_length = curve.GetLength()
offset = 160 # Fixed offset from both ends
if total_length <= 2 * offset:
return None # Avoid errors if the curve is too short
remaining_length = total_length - 2 * offset
segment_length = remaining_length / num_segments
# Generate division points along the curve
params = [curve.Domain.T0] # Start point
for i in range(1, num_segments):
success, param_at_length = curve.LengthParameter(offset + i * segment_length)
if success: # Only append if the parameter is valid
params.append(param_at_length)
params.append(curve.Domain.T1) # End point
points = [curve.PointAt(param) for param in params]
return th.list_to_tree(points)
# Ensure 'curve' is defined in Grasshopper inputs
division_points = divide_curve(curve, num_segments)