# Syntax in levels using code blocks

**URL:** https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834
**Category:** Lists-Logic
**Created:** [August 8, 2017, 6:01pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834 "2017-08-08T18:01:55Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![simoneavellini](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@simoneavellini](https://forum.dynamobim.com/u/simoneavellini)
#### Post date: [August 8, 2017, 6:01pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/1 "2017-08-08T18:01:55Z")

</div>

Hello,  
is there a way to achieve the follow using just the code block?  
Thanks

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/f/3ff574fc3b87db50e84bf36f48d0009c79e8d223.png)

---

<div class="post-metadata">

### Author: ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)
#### Post date: [August 8, 2017, 6:16pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/2 "2017-08-08T18:16:13Z")

</div>

The correct syntax for levels is `<n>` for the nth level list. I don’t think it works with the “shorthand” version of `list[n]` but you can use GetItemAtIndex to do the same thing: `DSCore.List.GetItemAtIndex(list<2>,0);`

---

<div class="post-metadata">

### Author: ![john\_pierson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/john_pierson/32/191977_2.png) [@john\_pierson](https://forum.dynamobim.com/u/john_pierson)
#### Post date: [August 8, 2017, 9:29pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/3 "2017-08-08T21:29:37Z")

</div>

I also use Node 2 Code a lot to learn the syntax.

 ![20170808-node2Code](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/e/0eff593dbcbd50c41439cb3741f8f55353eef708.gif)

---

<div class="post-metadata">

### Author: ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)
#### Post date: [August 8, 2017, 9:40pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/4 "2017-08-08T21:40:06Z")

</div>

Tip:  
Select the nodes you want to make a code block, right click the background, and select “node to code”.

---

<div class="post-metadata">

### Author: ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)
#### Post date: [August 8, 2017, 11:47pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/5 "2017-08-08T23:47:07Z")

</div>

![20170808-5](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/6/96c2fc31c3042f395d567c88d23880c0cee94685.png)

---

<div class="post-metadata">

### Author: ![simoneavellini](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@simoneavellini](https://forum.dynamobim.com/u/simoneavellini)
#### Post date: [August 9, 2017, 9:51am UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/6 "2017-08-09T09:51:18Z")

</div>

Thanks guys,  
I was after a shorthand for this, but apparently there is no way to avoid the use of List.GetItemAtIndex.  
Cheers.  
Simone

---

<div class="post-metadata">

### Author: ![PierreL](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@PierreL](https://forum.dynamobim.com/u/PierreL)
#### Post date: [November 17, 2019, 1:11pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/7 "2019-11-17T13:11:33Z")

</div>

Hey guys, quick taught on this : If I am right you want to get all the items at index zero for each list. A short hand for each one of them is Lst[listindex][objectindex] so :

Lst[0][0]  
Lst[1][0]  
Lst[2][0]  
…

The 0, 1, 2… are basicly the list length right?

You could probably shorthand this with something like  
L= 0…(len(lst)-1))  
YourItems = Lst[L][0]

I on my phone can’t check if this works but design script usually accepts list of integer replacing integer value and just repeats the process.

If it does not work go in imperative mode with [imperative] in the code block and try a python–like script with a “for” loop based on a list of index.

All the best  
P.

---

<div class="post-metadata">

### Author: ![jpTrujilloLevy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jptrujillolevy/32/13800_2.png) [@jpTrujilloLevy](https://forum.dynamobim.com/u/jpTrujilloLevy)
#### Post date: [December 8, 2022, 11:14pm UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/8 "2022-12-08T23:14:19Z")

</div>

Here is DesignScript Language Specification 2.1, which includes reference about this topic in chapters 9 and 10

> **[DesignScriptGuide.pdf](https://dynamobim.org/wp-content/links/DesignScriptGuide.pdf)**
>
> 460.12 KB

---

<div class="post-metadata">

### Author: ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)
#### Post date: [December 10, 2022, 11:19am UTC](https://forum.dynamobim.com/t/syntax-in-levels-using-code-blocks/13834/9 "2022-12-10T11:19:11Z")

</div>


