# How to create a Range with Multiple Step values?

Hello everyone,

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:

• Daan

Hi @Daan,
Something like this?

DoubleStepSequence.dyn (9.2 KB)

Option - 1

``````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``````
3 Likes

dashed.dyn (15.9 KB)

Or a line of Design Script
`List.Transpose([0..#c..(a+b),a..#c..(a+b)]);`

7 Likes

Thank you very much for both solutions!
I will try both out and see which ones work best for me!

Thanks again!!

1 Like

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

1 Like

Try making it a custom node.

2 Likes

A Custom Node? How would i approach that/ use that?
(I have never made a custom node btw)

`List.Transpose(List.Transpose([0..#(lgt/(lin+gap))..(lin+gap),lin..#(lgt/(lin+gap))..(lin+gap)])<1>);`

dashed2.dyn (11.2 KB)

3 Likes

This will help with that: Custom Nodes | The Dynamo Primer

1 Like

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

dashed3.dyn (11.2 KB)

`List.Transpose(List.Transpose([0..lgt..(lin+gap),List.AddItemToEnd(lgt<1>,(lin..lgt..(lin+gap))<1>)])<1>);`

2 Likes

Small update: i now know how to create custom nodes
I used your first Python script inside a custom node and it works perfect !

1 Like