#DesignScript LM – Chapter 17 Translation – Conditionals and Boolean Logic


Hi Everyone:

This translation is from the seventeenth chapter of the DesignScript Language Manual and can be found at DSLM  (pages 52-55) and is entitled; Conditionals and Boolean Logic. There also is a companion video tutorial entitled, Conditionals and Boolean Logic (#13), which can be found in the DS website’s tutorials.

The initial manual translation was made on the Autodesk DesignScript Community Forum and DesignScript.org. Now it can be found at can be found at Chapter 17: Conditionals and Boolean LogicCode to Node (Note that it can be not longer be found on the Autodesk Labs Website, as linked.)

Continuing, open the DS Editor and create a new file, lets copy and paste the first and second page of code from Chapter 14 (pages 52 & 54) into the Editor. Separate the code by commenting out the “import” statements at each pasted section of code in order to generate the graphic windows results in each subsequent page of code.

chp17 Conditionals and Boolean Logic_pg52 thru 55.ds#1

chp17 Conditionals and Boolean Logic_pg52 thru 55.ds#1

Now paste the same script into a blank canvas on DesignScript Studio.

chp17 Conditionals &Boolean Logic_pg55_a1

chp17 Conditionals &Boolean Logic_pg55_a1

Edited out the commenting out so the script will be activated, but first make sure that the “import” statements are commented out.

chp17 Conditionals &Boolean Logic_pg55_a1-edited

chp17 Conditionals &Boolean Logic_pg55_a1-edited

After commenting out the last bit of code then, the code-block is activated, and we are reminded that “Class and Function definitions are not supported in DesignScript Studio.”

Developing and breaking out the script into code blocks is shown in the DS Studio canvas in it’s initial translation.



In order to get a result we had to make a custom node as a work-around to the none supported definitions. For brevity sake this section is taken from DesignScript.org post.

Again, “due to the fact that class and function definitions are not supported in Design Script Studio, it was necessary to figure on some work a-round for this tutorial. When running (i % 2 == 0 || i % 3 == 0) in block form, one can get a return on the division remainder, but not the actual integers that are required.”

“The program suggests using a in line conditional, see page 12 of the DesignScript Summary Manual. DSSM  [ variable = boolean_expression ? expression_if_true : expression_if_false; ] together with the subject code, a variable and or integer could  be returned.”

While the in line conditional script…

(i%2==0 || i%3== 0) ? a : b;

returns either true or false, we can go further and wrap the inline conditions to a method as shown below…

def DivisibleBy2Or3(i : int, a : var, b : var)


return = (i%2==0 || i%3== 0) ? a  : b;


and then save it as ds file and finally…

booleanConditional_ DivisibleBy2Or3

booleanConditional_ DivisibleBy2Or3

load it into the DesignScript Studio library and the into the canvas as shown below.

chp17 Conditionals and Boolean Logic_pg55_1a_load

chp17 Conditionals and Boolean Logic_pg55_1a_load

This results in the graph node titled “DivisibleBy2or3“.

Continuing, a more detailed and defined translation was done and involved naming the variables to identify and reference into them to their corresponding nodes.

chp17 Conditionals and Boolean Logic_pg55_1a-left

chp17 Conditionals and Boolean Logic_pg55_1a-left

Then with the naming and identifying complete,  the “Node to Code” operation can take place.

chp17 Conditionals& Boolean Logic_pg55_1b

chp17 Conditionals& Boolean Logic_pg55_1b

One must remember to make sure the custom node is still present in the Library, otherwise just reload it and reinitialize the code. We see that a little editing is in order as highlighted above.

chp17 Conditionals and Boolean Logic_pg55_1b-edited

chp17 Conditionals and Boolean Logic_pg55_1b-edited

The Windows Graphic that is generated from the files is shown below.

chp17-Boolean_conditional_node-1_Graphic Window

chp17-Boolean_conditional_node-1_Graphic Window

Note that colors were added in this translation, to highlight the geometry in the Graphic view window.

Reiterating, this was done on the stand-alone version of DesignScript, rather than as a plugin for AutoCAD. The files are available for downloading from the Drop-Box links below.

2015_02_11-chp17 Conditionals Boolean Logic_pg55_a1





Thanks for looking.






Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s