# Code Block- Function

**URL:** <https://forum.dynamobim.com/t/code-block-function/6490>\
**Category:** DesignScript\
**Created:** [October 2, 2016, 5:05am UTC](https://forum.dynamobim.com/t/code-block-function/6490 "2016-10-02T05:05:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dangthanhnam01.kt199](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dangthanhnam01.kt199/32/83686_2.png) [@dangthanhnam01.kt199](https://forum.dynamobim.com/u/dangthanhnam01.kt199)\
**Post date:** [October 2, 2016, 5:05am UTC](https://forum.dynamobim.com/t/code-block-function/6490/1 "2016-10-02T05:05:24Z")

</div>

I’m trying to use blocks of code to solve the problem instead of using the buttons on the dynamo. This is what I am seeking to do.

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/9/956b96cba643441554e02f5357229128a47bf41b.png)

---

<div class="post-metadata">

**Author:** ![dangthanhnam01.kt199](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dangthanhnam01.kt199/32/83686_2.png) [@dangthanhnam01.kt199](https://forum.dynamobim.com/u/dangthanhnam01.kt199)\
**Post date:** [October 2, 2016, 7:27pm UTC](https://forum.dynamobim.com/t/code-block-function/6490/2 "2016-10-02T19:27:53Z")

</div>

I’m trying to understand how the code block works through the example above. I’d love to find answers to problems. Thank you for reading. 🙂

---

<div class="post-metadata">

**Author:** ![Jan\_Secnik](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jan_secnik/32/55692_2.png) [@Jan\_Secnik](https://forum.dynamobim.com/u/Jan_Secnik)\
**Post date:** [October 3, 2016, 9:05am UTC](https://forum.dynamobim.com/t/code-block-function/6490/3 "2016-10-03T09:05:46Z")

</div>

try using While instead of For, dont know why but in some cases it helps.

---

<div class="post-metadata">

**Author:** ![Organon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/organon/32/161404_2.png) [@Organon](https://forum.dynamobim.com/u/Organon)\
**Post date:** [October 3, 2016, 5:48pm UTC](https://forum.dynamobim.com/t/code-block-function/6490/4 "2016-10-03T17:48:45Z")

</div>

Could you paste the block of code, drop the file or something? Thanks.

---

<div class="post-metadata">

**Author:** ![dangthanhnam01.kt199](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dangthanhnam01.kt199/32/83686_2.png) [@dangthanhnam01.kt199](https://forum.dynamobim.com/u/dangthanhnam01.kt199)\
**Post date:** [October 5, 2016, 3:03pm UTC](https://forum.dynamobim.com/t/code-block-function/6490/5 "2016-10-05T15:03:12Z")

</div>

hi Organon. Thanks for answering. This is my file  
[BT Cau tao.dyn](https://forum.dynamobim.com/uploads/short-url/5NI9WRQW3qMgAPkg8BAQgwEtWic.dyn) (36.3 KB)

---

<div class="post-metadata">

**Author:** ![dangthanhnam01.kt199](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dangthanhnam01.kt199/32/83686_2.png) [@dangthanhnam01.kt199](https://forum.dynamobim.com/u/dangthanhnam01.kt199)\
**Post date:** [October 5, 2016, 3:44pm UTC](https://forum.dynamobim.com/t/code-block-function/6490/6 "2016-10-05T15:44:53Z")

</div>

I think the problem is here

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

---

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [October 5, 2016, 3:51pm UTC](https://forum.dynamobim.com/t/code-block-function/6490/7 "2016-10-05T15:51:10Z")

</div>

The problem is that you decalre the arguments for sl, x, and bk1 as lists when they are scalars. DesignScript therefore expects list. As you are using an imperative block the entire ‘list’ is used to calculate t1 and the radius of the circle. Since you havent provided a list the calculations fails which is why you get nulls. Even if you gave it lists for all the arguments it would still fail as you would need to index.

Here’s the fix:

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/0/0ed6130995491d3c7935eda8b105c5d9c73404e3.jpg)

```
def dt(sl:int,x:int,bk1:int,npoint:var[])
{
	return =[Imperative]
	{
		t1 = x/sl;

		t2 = {};
		for ( i in GetKeys(npoint) )
		{
			t2[i] = Circle.ByCenterPointRadius(npoint[i], bk1 + i* t1);
		}
		return = t2;
	}
};

dt(sl, x, bk1, npoint);
```

---

<div class="post-metadata">

**Author:** ![dangthanhnam01.kt199](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dangthanhnam01.kt199/32/83686_2.png) [@dangthanhnam01.kt199](https://forum.dynamobim.com/u/dangthanhnam01.kt199)\
**Post date:** [October 5, 2016, 4:01pm UTC](https://forum.dynamobim.com/t/code-block-function/6490/8 "2016-10-05T16:01:03Z")

</div>

You are always solved my problems. :nụ cười:  
Thank you very much

---

<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:** [October 7, 2016, 4:21am UTC](https://forum.dynamobim.com/t/code-block-function/6490/9 "2016-10-07T04:21:47Z")

</div>

![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/3/37752c6352ee92df29dcf492490c51e790de688c.png)

`Circle.ByCenterPointRadius(Point.Origin(),st..#5..sp);`
