> For the complete documentation index, see [llms.txt](https://primer2.dynamobim.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://primer2.dynamobim.org/8_coding_in_dynamo/8-1_code-blocks-and-design-script/3-shorthand.md).

# Shorthand

### Shorthand

There are a few basic shorthand methods in the code block which, simply put, make data management *a lot* easier. We'll break down the basics below and discuss how this shorthand can be used both for creating and querying data.

| **Data Type**          | **Standard Dynamo**                                                                                                                                                                                                                                                          | **Code Block Equivalent**                                                                                                                                                                                                                                                         |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Numbers                | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-cf00948307be3adbe82da8f5d2277c9301d54b46%2F01%20node%20-%20numbers.jpg?alt=media\&token=0c95ae2b-ba0c-4760-bc2f-60f1677508e6)           | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-695d2c639d31e7122152a2e243254dc2d921f912%2F01%20codeblock%20-%20numbers.jpg?alt=media\&token=af997d44-d09d-48e9-a408-e918b3e10fb3)           |
| Strings                | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-07a610a540f64c78c11cd31b2f736dd07d8a79b1%2F02%20node%20-%20string.jpg?alt=media\&token=427bb3c7-ecc1-4d31-9dc1-0eb428865dca)            | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-f6c20d858ffb2b1dc1929f122199073c675aaa0d%2F02%20codeblock-%20string.jpg?alt=media\&token=3255b2b1-ffdc-4e3a-9a99-c10e5ff66183)               |
| Sequences              | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-b37cc7762cfbdb4dd3ff73e7373cb2348644817b%2F03%20node-%20sequence.jpg?alt=media\&token=18423bf5-87f0-4958-976c-b89460590208)             | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-34ddfeb480f688e115a06e8c981c873b4a04d000%2F03%20codeblock-%20sequence.jpg?alt=media\&token=98e647ba-ae73-41e5-b99d-9ff94ad2f12e)             |
| Ranges                 | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-b72e3950946b9cf0a56951c49658377ccb2174ac%2F04%20node-%20range.jpg?alt=media\&token=7fe20bfc-0d24-4eee-a74e-44a29c2cf044)                | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-33e200f789bd61051207bfb3160d48ec96742cd9%2F04%20codeblock%20-%20range.jpg?alt=media\&token=8b983332-0eaf-434a-a058-374f1b54026a)             |
| Get Item at Index      | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-5c8d1c0b21dc56a3f244a3fff128f013f7c0e492%2F05%20node%20-%20list%20get%20item.jpg?alt=media\&token=dfe9d0ab-143a-4973-8a8e-623bb1a853c2) | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-2157b39389ccd961dd4f54b09d3db0babd8b0898%2F05%20codeblock%20-%20list%20get%20item.jpg?alt=media\&token=c1f49be3-58a0-47e0-9448-fca8b64ad2ee) |
| Create List            | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-3dc2ee4a5adbe64a6361d2096b65d1e3794be13c%2F06%20node%20-%20list%20create.jpg?alt=media\&token=62825d1a-ba2c-4ce3-b35f-2f0a42095872)     | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-1aa8e3a96f0de1664391689b1f8f6244e7aee6ff%2F06%20codeblock%20-%20list%20create.jpg?alt=media)                                                 |
| Concatenate Strings    | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-b3c43836bc31bacfc1ca3bd4ede63ab1e8f5bf6a%2F07%20node%20-%20string%20concat.jpg?alt=media\&token=046bc236-89f1-413b-a5f4-245f3fbaa548)   | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-e146750e8c5cdbca801a81dca4d8cbc3744c91d9%2F07%20codeblock%20-%20string%20concat.jpg?alt=media\&token=9b06b507-6cf0-4236-91fc-cc7ffb23439b)   |
| Conditional Statements | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-b7b2270a5db5c0247d5bcf9fca90a4958f10efe1%2F08%20node%20-%20conditional.jpg?alt=media\&token=7c1b5c11-682e-4a19-ba2a-bf2576382a7c)       | ![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-0bf58251f548d06a9f50b93d6750206019367123%2F08%20codeblock%20-%20conditional.jpg?alt=media\&token=dbc2e065-40fd-40d5-953c-5de28fd53b3a)       |

### Additional Syntax

|                                     |                           |                                                                                          |
| ----------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------- |
| **Node(s)**                         | **Code Block Equivalent** | **Note**                                                                                 |
| Any operator (+, &&, >=, Not, etc.) | +, &&, >=, !, etc.        | Note that “Not” becomes “!” but the node is called “Not” to distinguish from “Factorial” |
| Boolean True                        | true;                     | Note lower case                                                                          |
| Boolean False                       | false;                    | Note lower case                                                                          |

### Ranges and Sequences

The method for defining ranges and sequences can be reduced to basic shorthand. Use the image below as a guide to the ".." syntax for defining a list of numerical data with code block. After getting the hang of this notation, creating numerical data is a really efficient process:

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-1494f48b817f5a0314df0c7415269187f6fc594e%2Fshorthand%20-%20ranges%20and%20sequences.jpg?alt=media\&token=109d54d8-c5b2-4527-bc4c-fabeb9deb404)

> 1. In this example, a number range is replaced by basic **Code Block** syntax defining the `beginning..end..step-size;` . Represented numerically, we get: `0..10..1;`
> 2. Notice that the syntax `0..10..1;` is equivalent to `0..10;` A step-size of 1 is the default value for the shorthand notation. So `0..10;` will give a sequence from 0 to 10 with a step-size of 1.
> 3. The *Sequence* example is similar, except we use a "#" to state that we want 15 values in the list, rather than a list which goes up to 15. In this case, we are defining: `beginning..#ofSteps..step-size:` The actual syntax for the sequence is `0..#15..2`
> 4. Using the *"#"* from the previous step, we now place it in the *"step-size"* portion of the syntax. Now, we have a *number range* spanning from the *"beginning"* to the *"end"* and the *"step-size"* notation evenly distributes a number of values between the two: `beginning..end..#ofSteps`

### Advanced Ranges

Creating advanced ranges allows us to work with list of lists in a simple fashion. In the examples below, we're isolating a variable from the primary range notation, and creating another range of that list.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-54ed83edea35de7c0bb483562eb5ec0ecf540b71%2Fshorthand%20-%20advance%20range%2001.jpg?alt=media\&token=0fa712fd-be0f-43a6-9ab7-f75058164378)

> 1\. Creating nested ranges, compare the notation with a "#" vs. the notation without. The same logic applies as in basic ranges, except it gets a little more complex.
>
> 2\. We can define a sub-range at any place within the primary range, and notice that we can have two sub-ranges as well.
>
> 3\. By controlling the "end" value in a range, we create more ranges of differing lengths.

As a logic exercise, compare the two shorthands above and try to parse through how *subranges* and the *#* notation drive the resultant output.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-cba9a96dccf9dd4e024513ecc88747762f6c7ca0%2Fshorthand%20-%20advance%20range%2002.jpg?alt=media\&token=8d27d09b-69b0-4618-9be2-bee2259080a6)

### Make Lists and Get Items From a List

In addition to making lists with shorthand, we can also create lists on the fly. These list can contain a wide range of element types and can also be queried (remember, lists are objects in themselves). To summarize, with code block you make lists and query items from a list with brackets (a.k.a. “square brackets”):

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-5ae2e9ee7a9b96d93b39831e5b757f6a8f0dd2c2%2Fshorthand%20-%20list%20%26%20get%20from%20list%2001.jpg?alt=media\&token=cd497660-2c08-4adc-9d02-5f8b52c76e37)

> 1\. Create lists quickly with strings and query them using the item index.
>
> 2\. Create lists with variables and query using the range shorthand notation.

Managing with nested lists is a similar process. Be aware of the list order and recall using multiple sets of square brackets:

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-d14b423125662ca4a526d8ad43f86dacb3605edc%2Fshorthand%20-%20list%20%26%20get%20from%20list%2002.jpg?alt=media\&token=cc07dba7-0578-4bb0-8f93-39f5115d1a4c)

> 1\. Define a list of lists.
>
> 2\. Query a list with single bracket notation.
>
> 3\. Query an item with double bracket notation.

## Exercise: Sine Surface

> Download the example file by clicking on the link below.
>
> A full list of example files can be found in the Appendix.

{% file src="/files/VTlSL2XVkMvjxiLVWliN" %}

In this exercise, we will flex our new shorthand skills to create a funky-cool eggshell surface defined by ranges and formulas. During this exercise, notice how we use code blocks and existing Dynamo nodes in tandem: we use the code blocks for the heavy data lifting while the Dynamo nodes are visually laid out for legibility of the definition.

Start by creating a surface by connecting the nodes above. Instead of using a number node to define width and length, double click on the canvas and type `100;` into a code block

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-863f2743099c698534fd14d082de1af96041b448%2Fshorthand%20-%20exercise%2001.jpg?alt=media\&token=2b95eed2-0f8e-4547-ab71-22e411dce4d1)

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-9e0969b2b85f4bc91366c56a5125ce0c9ae3367d%2Fshorthand%20-%20exercise%2002.jpg?alt=media\&token=58222a1c-0bee-4ccf-add5-0d84668ad47d)

> 1. Define a range between 0 and 1 with 50 divisions by typing `0..1..#50` into a **Code Block**.
> 2. Connect the range into **Surface.PointAtParameter**, which takes u and v values between 0 and 1 across the surface. Remember to change the Lacing to Cross Product by right clicking on the **Surface.PointAtParameter** node.

In this step, we employ our first function to move the grid of points up in the Z. This grid will drive a generated surface based on the underlying function. Add new nodes as shown in image below

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-83286fc3d84d27678367aeb37966a7aa4368bbbb%2Fshorthand%20-%20exercise%2003.jpg?alt=media\&token=79ab07d0-998f-4265-a5e2-cc1a5da87b5f)

> 1. We use a **Code Block** with the line: `(0..Math.Sin(x*360)..#50)*5;`. To quickly break this down, we're defining a range with a formula inside of it. This formula is the Sine function. The sine function receives degree inputs in Dynamo, so in order to get a full sine wave, we multiple our x values (this is the range input from 0 to 1) by 360. Next we want the same number of divisions as control grid points for each row, so we define fifty subdivisions with #50. Finally, the multiplier of 5 simply increases the amplitude of translation so that we can see the effect in the Dynamo Preview.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-78eb81e06fb0897ccc0a9292e39293991b25b1de%2Fshorthand%20-%20exercise%2004.jpg?alt=media\&token=569ed523-5121-45c6-a640-390772b1daab)

> 1. While the previous **Code Block** worked fine, it wasn't completely parametric. We want to dynamically drive its parameters, so we'll replace the line from the previous step with `(0..Math.Sin(x*360*cycles)..#List.Count(x))*amp;`. This gives us the ability to define these values based on inputs.

By changing the sliders (ranging from 0 to 10), we get some interesting results.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-34d3dd948c9605259f12e3585520de4c571dcff5%2Fshorthand%20-%20exercise%2005.gif?alt=media\&token=5fd07e09-0d7c-4471-87c7-18224e3eb5d8)

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-a159a3ff4fcad617e9f9d5b50105b8a4db03bbdc%2Fshorthand%20-%20exercise%2006.jpg?alt=media\&token=5532431d-d892-415c-b4aa-b874c2bd6b84)

> 1. By doing a transpose on the number range, we reverse the direction of the curtain wave: `transposeList = List.Transpose(sineList);`

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-fe21fba9e59543f7fcad91285f7d52189a1bedbe%2Fshorthand%20-%20exercise%2007.jpg?alt=media\&token=4a3204f1-47c3-4bc7-8699-c9b7210010fc)

> 1. We get a distorted eggshell surface when we add the sineList and the transposeList: `eggShellList = sineList+transposeList;`

Let's change the sliders values specified below to 'calm the waters' of this algorithm.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-05caf4132ee0d359938340c0ef88bed7a7f2f230%2Fshorthand%20-%20exercise%2008.jpg?alt=media\&token=23f567be-ce68-4a09-ba4d-8b3571fbae7b)

Last, let's query isolated parts of the data with the Code Block. To regenerate the surface with a specific range of points, add the code block above between the **Geometry.Translate** and **NurbsSurface.ByPoints** node. This has the line of text: `sineStrips[0..15..1];`. This will select the first 16 rows of points (out of 50). Recreating the surface, we can see that we've generated an isolated portion of the grid of points.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-572b70cde0e8fe2a2e437b2cee8c0e3e08fa8bde%2Fshorthand%20-%20exercise%2009.jpg?alt=media\&token=949e299b-5a9c-4e61-a422-7fcb2b25f77c)

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-78ef75b165a2de888054bbbbe9460cff974c827c%2Fshorthand%20-%20exercise%2010.jpg?alt=media\&token=b5d1da41-b225-458d-8bc5-90d39e94d45a)

> 1. In the final step, to make this **Code Block** more parametric, we drive the query by using a slider ranging from 0 to 1. We do this with this line of code: `sineStrips[0..((List.Count(sineStrips)-1)*u)];`. This may seem confusing, but the line of code gives us a quick way to scale the length of the list into a multiplier between 0 and 1.

A value of `0.53` on the slider creates a surface just past the midpoint of the grid.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-6a4ed21cf4a48ea566666ca10ceda4a180c93a6d%2Fshorthand%20-%20exercise%2011.jpg?alt=media\&token=ce1561e4-1a96-4aea-976f-29ebbceb1442)

And as expected, a slider of `1` creates a surface from the full grid of points.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-6c3a9b1cc8ca615f627b33b2c9ad33092caa364b%2Fshorthand%20-%20exercise%2012.jpg?alt=media\&token=66a56e4d-6b18-4cbd-aed6-170b5627bcfb)

Looking at the visual graph, we can highlight the code blocks and see each of their functions.

![](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-da9dfd733c467011497cf8ff226f89c3480b93f3%2Fshorthand%20-%20exercise%2013.jpg?alt=media\&token=1d039d63-ec8f-4b7d-b7d6-9dee0199f94c)

> 1\. The first **Code Block** replaces the **Number** node.
>
> 2\. The second **Code Block** replaces the **Number Range** node.
>
> 3\. The third **Code Block** replaces the **List.Transpose**, **List.Count** and **Number Range** nodes.
>
> 4\. The fourth **Code Block** queries a list of lists, replacing the **List.GetItemAtIndex** node.
