I think it’s lines 30 and 35 causing the issue… But because I am enumerating through the points the list length has to match the length of the list of letters.

There are some issues in your code, especially regarding the vectors you’ve hard coded into your system, since you’re getting more lines and gaps each iteration this gap should become narrower and narrower, however that’s not possible since you have pre-defined the Vector lengths.

See if this helps:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Parameters
TOTAL_ITERATIONS = 5
INITIAL_LENGTH = 100.0
Y_DISTANCE = 20.0
def generate_cantor_set(start_x, end_x, y, iteration):
lines = []
if iteration >= 0:
lines.append(Line.ByStartPointEndPoint(Point.ByCoordinates(start_x, y, 0), Point.ByCoordinates(end_x, y, 0)))
if iteration > 0:
segment_length = (end_x - start_x) / 3.0
next_y = y + Y_DISTANCE # Use Y to offset each iteration
lines.extend(generate_cantor_set(start_x, start_x + segment_length, next_y, iteration - 1))
lines.extend(generate_cantor_set(end_x - segment_length, end_x, next_y, iteration - 1))
return lines
# Generate Cantor set
OUT = generate_cantor_set(0, INITIAL_LENGTH, 0, TOTAL_ITERATIONS - 1)