• Up next:Set Family Types

Random Numbers in Dynamo

0:00 / 0:00

1-2 Generate Random Numbers in Dynamo – Practice Exercise

In this exercise, we will create a list of random numbers in Dynamo

Task 1: Open Revit and Dynamo

  1. Open Revit 2021 then open the “Random Numbers Dynamo_sample project_2021.rvt” sample file provided with this lesson.
  2. In the “Manage” ribbon, click the “Dynamo” button to launch Dynamo.
  3. Once Dynamo opens, click the “New” button to create a new script file

 

Task 2: Install the Clockwork package (if it is not installed already)

  1. Check your node library to see if the “Clockwork” package is installed.

 

 

  1. If you do not see it, click “Packages” in the menu bar then click “Search for a Package”.
  2. Type “Clockwork” in the search bar.
  3. Click the download arrow next to “Clockwork for Dynamo 2.x” in the results window to install the package.

 

Task 3: Define parameters for random number list

  1. You are going to generate a list of random numbers ranging from 1 to 5. To do this, double click an empty space in the Dynamo workspace to create a node block.
  2. In the Code Block, type the number 1 followed by a semicolon in the code block. Press the “Enter” key to create a new line.
  3. Type the number 5 followed by a semicolon. Press the “Enter” key to create a new line.
  4. Type the number 100 followed by a semicolon.
  5. Your code block should look like the following:


Task 3: Create the random number list

  1. In the node library, navigate to the “Clockwork” category.
  2. In “Clockwork”, click the “List” category then click the “RandomList” sub-category.
  3. Click the “AsIntegers” node to add it to your script.
  4. Connect the output from the number 1 in the Code Block to the “min” input of the RandomList.AsIntegers node.
  5. Connect the output from the number 5 in the Code Block to the “max” input of the RandomList.AsIntegers node.
  6. Connect the output from the number 100 in the Code Block to the “amount” input of the RandomList.AsIntegers node.
  7. These inputs will generate 100 random numbers ranging from 1 to 5.


Task 4: Add number slider

  1. You want to interactively generate the list of numbers so we’ll use a Number Slider to specify the “seed” input of the RandomList.AsIntegers node.
  2. Type “number slider” in the node library search bar. Click to add the Integer Slider to your script.
  3. Connect the output of the Number Slider to the “seed” input of the RandomList.AsIntegers node.
  4. Type “watch” in the node library search bar and click the add a Watch node to your script.
  5. Connect the output of the RandomList.AsIntegers node to the watch node.
  6. Adjust the slider on the Number Slider and observer the results in the Watch node.
  7. Your script should look like this:

 

 

Task 5: Group the Nodes

  1. Pick a spot in the upper left of the Dynamo workspace and click and hold the left mouse button.
  2. Drag the selection window to the lower right-hand corner to select all of the nodes.
  3. Right-click and click the “Create Group” option.
  4. Double click the group title and type “Generate Random Numbers”.
  5. Right-click the group and select a new color
  6. In the menu bar, click Save to save your Dynamo script file. 
  • Up next:Set Family Types