I have a small problem in the logic of my script. I want to split a line by distance in my script.
For example every 3 meters the curve, then every other 3 meters and so on).
The catch however, is the fact that these 2 numbers (3 & 3) are input values, so they can be whatever number i need. So 1 & 3 and 3 & 9 are also inputs which should work.
I was thinking about using a code block with something like this, but i couldn’t figure out how to use multiple distances:
sumNums = IN[2] + IN[3]
start = IN[0]
sum = start
rangeList = [start]
x = IN[3]
while sum < IN[1]:
x = sumNums - x
sum = sum + x
if sum < IN[1]:
rangeList.append(sum)
OUT = rangeList
Option - 2
inputs = IN[0].split("..")
def num(s):
try:
return int(s)
except ValueError:
return float(s)
sumNums = num(inputs[2]) + num(inputs[3])
start = num(inputs[0])
sum = start
rangeList = [start]
x = num(inputs[3])
while sum < num(inputs[1]):
x = sumNums - x
sum = sum + x
if sum < num(inputs[1]):
rangeList.append(sum)
OUT = rangeList
First of all, both solutions work great if i have a single input, but the problem is that it is almost always possible that i have multiple curves which need to be split like this.
This is what i have so far, maybe you guys know how to improve this
Hey Vikram, my solution wasn’t fully working for me because i need to start at “line” instead of gap, but when i try to use your method, the last line gets cut of, but it could still fit.
Also i need the line to be created, even if the line is not the full length (example, if 1 meter line doesnt fit, but 0.5 does, use 0.5 as length for the last line.
The definition below should address that, but it could sometimes try to create a line of 0 length at the end. You’ll need to extend and improve the definition to eliminate such issues