where buildings and technology collide…
Show MenuHide Menu

Using Code Blocks to create lists of numbers

15th September 2015

Love them or hate them, Code Blocks in Dynamo can be exceptionally powerful, but working out all of the different syntaxes is nearly impossible. So here’s a list of the ones that I know about. Please leave a comment if you know any more!

You can do all of these either in a Number node or in a Code Block. The result is the same.

Create a list of numbers

The first one is simple – create a list of numbers. The syntax is:

StartValue..UpperBound

This will create a list of numbers starting at the StartValue and increasing in steps of 1.0 until it reaches the UpperBound. Note that we’re using an upper bound rather than an end value – you wont necessarily get the upper bound value as a number in your list, depending on the values you pick…

HowToCodeBlock_01

 

Number list with custom spacing

You can change the step size in your list of numbers by adding an extra bit to the end of the syntax:

StartValue..UpperBound..StepSize

HowToCodeBlock_02

List of approximate values

What if you want to make sure you hit your end value, but you aren’t too bothered about whether the step size is exactly as you have input. No problem, you can use this syntax to get the closest available match. This will adjust the spacing to hit your end value exactly:

0..5..~0.75

HowToCodeBlock_04

What if you want to use sliders?

Everybody loves sliders, no problem. Replace any or all of the values with a string to extract it as an input.

HowToCodeBlock_05

Create a number list with a start and end value

In this option you get to specify the StartValue, the EndValue and the NumberOfValues you want. The syntax goes like this:

StartValue..EndValue..#NumberOfValues

HowToCodeBlock_03

 

But what if you want MORE?

This is just the tip of the iceberg when it comes to what you can do with a Code Block. There is a great post about Code Blocks on the Dynamo website. Check it out and get creative!

Finally, if you're really keen, check out this link to the Dynamo Language Guide.