# DesignScript Question

**URL:** <https://forum.dynamobim.com/t/designscript-question/37450>\
**Category:** DesignScript\
**Tags:** designscript\
**Created:** [June 21, 2019, 7:54am UTC](https://forum.dynamobim.com/t/designscript-question/37450 "2019-06-21T07:54:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnoordzij](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jnoordzij/32/32419_2.png) [@jnoordzij](https://forum.dynamobim.com/u/jnoordzij)\
**Post date:** [June 21, 2019, 7:54am UTC](https://forum.dynamobim.com/t/designscript-question/37450/1 "2019-06-21T07:54:52Z")

</div>

Hi,

In the screenshot, please have a look at the different results at the two red arrows.  
Why is the first code block returning a value and the second codeblock returning null?  
Both seem to be executing the same line of code?  
Is there a mistake in the definition code block?

definition code underneath

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

```
def check (X,Y,T){
return = [Imperative]{
	if(T){
			if(Y>0){
			return = Math.Atan(X/Y)+180;
			}
			else{
			return = Math.Atan(X/Y);
			};
		}
	else {
			if(Y>0){
			return = Math.Atan(X/Y)+90;
			}
			else{
			return = Math.Atan(X/Y)-90;
			};

		}
  }
};
```

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [June 21, 2019, 9:11pm UTC](https://forum.dynamobim.com/t/designscript-question/37450/2 "2019-06-21T21:11:27Z")

</div>

Hello Jnoordzij,

I’ve copied your code through and it appears to be working for me with a test case. Is this still failing for you?

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

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [June 21, 2019, 9:14pm UTC](https://forum.dynamobim.com/t/designscript-question/37450/3 "2019-06-21T21:14:43Z")

</div>

what version of Dynamo is this @jnoordzij - you’re likely hitting a bug that was fixed with namespaced functions in imperative blocks.  
I believe it was fixed in 2.1

you can use a workaround like  
func = math.Atan;  
[imperative]

then inside the imperative block  
use func instead of math.Atan.

---

<div class="post-metadata">

**Author:** ![jnoordzij](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jnoordzij/32/32419_2.png) [@jnoordzij](https://forum.dynamobim.com/u/jnoordzij)\
**Post date:** [June 22, 2019, 8:37am UTC](https://forum.dynamobim.com/t/designscript-question/37450/4 "2019-06-22T08:37:21Z")

</div>

Thanks guys. I’ll give that a try.  
Using Dynamo 2.0.3 by the way.

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [June 22, 2019, 5:34pm UTC](https://forum.dynamobim.com/t/designscript-question/37450/5 "2019-06-22T17:34:50Z")

</div>

I think this might help:

> <https://github.com/DynamoDS/Dynamo/issues/8796>

---

<div class="post-metadata">

**Author:** ![jnoordzij](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jnoordzij/32/32419_2.png) [@jnoordzij](https://forum.dynamobim.com/u/jnoordzij)\
**Post date:** [June 24, 2019, 6:42am UTC](https://forum.dynamobim.com/t/designscript-question/37450/6 "2019-06-24T06:42:38Z")

</div>

Hello guys,

I tried defining a function outside the imperative block, as you suggested. But I’m still getting None.  
I will try upgrading to 2.1.

\*Edit: I see that there exists no Dynamo Revit version newer to the 2.0.3 that I’m using now.  
So I guess upgrading is not a real option.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/2/428ced9af68b84b8b5480b82333e1635cffb298a.png)

---

<div class="post-metadata">

**Author:** ![jnoordzij](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jnoordzij/32/32419_2.png) [@jnoordzij](https://forum.dynamobim.com/u/jnoordzij)\
**Post date:** [June 25, 2019, 7:27am UTC](https://forum.dynamobim.com/t/designscript-question/37450/7 "2019-06-25T07:27:22Z")

</div>

What version of Dynamo are you using @solamour?

Does upgrading Dynamo Core to 2.1 also fix this issue for Dynamo Revit 2.0.3?  
I tried upgrading to 2.1 but I ran into another issue, posted [here](https://forum.dynamobim.com/t/installing-latest-dynamocoreruntime-zip/37519), maybe you can help me with that?

@Michael_Kirschner2 maybe you can have a look as well?

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [June 25, 2019, 2:15pm UTC](https://forum.dynamobim.com/t/designscript-question/37450/8 "2019-06-25T14:15:22Z")

</div>

I’m using Dynamo Sandbox 2.2.0.4667 right now. You can read more about how to get this on the blog: [https://dynamobim.org/a-new-way-to-get-dynamo-sandbox/](https://dynamobim.org/a-new-way-to-get-dynamo-sandbox/) 🙂

Mike’s suggestion was as follows - embedding func inside the Definition, but outside of the Imperative section. This is a workaround to a bug that exists and is on our radar:

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

```auto
def check (X,Y,T){
func = Math.Atan;
return = [Imperative]{
	if(T){
			if(Y>0){
			return = func(X/Y)+180;
			}
			else{
			return = func(X/Y);
			};
		}
	else {
			if(Y>0){
			return = func(X/Y)+90;
			}
			else{
			return = func(X/Y)-90;
			};

		}
  }
};
```
