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 Logic–Code 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.
Now paste the same script into a blank canvas on DesignScript Studio.
Edited out the commenting out so the script will be activated, but first make sure that the “import” statements are commented out.
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…
load it into the DesignScript Studio library and the into the canvas as shown below.
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.
Then with the naming and identifying complete, the “Node to Code” operation can take place.
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.
The Windows Graphic that is generated from the files is shown below.
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
2013_10_21-chp17-Boolean_conditional_node-1
2014_02_15-Chp17_Conditionals&Boolean_Logic-1a
2015_02_12-Chp17_Conditionals&Boolean_Logic-1b
Thanks for looking.
T!M