Using Dynamo Code Blocks to create lists of numbers
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!
I’m not going to go into using functions and calling nodes from a Code Block, but there are lots of options here too. Check out the links at the bottom of the post.
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…
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
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
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.
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
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.