Range function in python script

Hello.
I am trying to learn PythonScript within dynamo and ran into a problem.
It happens that I want to create a range with data as it was done in a CODEBLOCK but it happens that it gives an error and it only admits integers on the other hand I cannot place quantity limits with the “#” either and it becomes a problem I thought it would be as simple as in the CODEBLOCK.
My request is how could I create a FUNCTION in PYTHONSCRIPT that allows me to enter integer and decimal values as well as allow me to enter quantity limits… in a nutshell, how could I replicate the function that the codeblock has in terms of ranges…?? ?
I leave some reference images there… I haven’t started anything CODE because I don’t understand how I should start… thank you very much for your help.


import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')

start = IN[0]
stop = IN[1]
step = IN[2]

OUT = range(start, stop, step)

You need to click on “+” in the python node to create 3 inputs and connect your values (start, stop, step) accordingly.

A good start with python in dynamo is this:

1 Like

Good morning, thanks for commenting… I’ve tried what you suggested but it doesn’t work… the range method keeps asking only for integers… how to enter decimal numbers…??? ?

Hello,
you can build custom generators (works on both engine)

drange

import sys
import clr

def drange(start, end, step):
	i = start
	while round(i, 10) < end:
		yield i
		i += step
		
OUT = list(drange(IN[0], IN[1], IN[2]))

linspace

import sys
import clr

def linspace(start, end, num):
	step = (end - start) * 1.0 / num 
	i = start
	while round(i, 10) < end:
		yield i
		i += step
		
OUT = list(linspace(IN[0], IN[1], IN[2]))

or you can use numpy with CPython3

4 Likes