# DesignScript Flatten not working in Function

**URL:** <https://forum.dynamobim.com/t/designscript-flatten-not-working-in-function/65881>\
**Category:** DesignScript\
**Tags:** revit, dynamo\
**Created:** [July 6, 2021, 1:12pm UTC](https://forum.dynamobim.com/t/designscript-flatten-not-working-in-function/65881 "2021-07-06T13:12:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mepdot](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mepdot/32/106281_2.png) [@Mepdot](https://forum.dynamobim.com/u/Mepdot)\
**Post date:** [July 6, 2021, 1:12pm UTC](https://forum.dynamobim.com/t/designscript-flatten-not-working-in-function/65881/1 "2021-07-06T13:12:04Z")

</div>

Dear All,

I just converted the graph into Node to Code and trying to use that code to define a function. Which will be used multiple times in my graph. As you can see the out was different in both the code blocks.

# Flatten inside my function is not working I think

can anyone help why the output is different in both cases?

[Family.dyn](https://forum.dynamobim.com/uploads/short-url/4nmMXfC38Y9ekzLiKPWhBDw6GIX.dyn) (19.6 KB)

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

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [July 6, 2021, 2:25pm UTC](https://forum.dynamobim.com/t/designscript-flatten-not-working-in-function/65881/2 "2021-07-06T14:25:49Z")

</div>

Hi @Mepdot

> [@Mepdot](#):
>
> can anyone help why the output is different in both cases?

You where missing tab and you need to define your inputs as var:

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

Here is the edited function:

```auto
def CategoryFamily(in1: var[]..[],in2: var[]..[])
{
	element1 = Revit.Elements.Element.ElementType(in1);
	familyinstance1 = Revit.FamilyInstance.ByFamilyType(element1);
	family1 = Revit.FamilyInstance.GetFamily(familyinstance1);
	t3 = DSCore.List.Flatten(family1, -1);
	t4 = DSCore.List.UniqueItems(t3);
	t5 = DSCore.List.Count(t4);
	t6 = DSCore.List.AddItemToFront(in2,t4);
	t7 = DSCore.List.AddItemToFront(t5,t6);
	return t7;
};

```

Edit:  
Another method with few lines:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/9/898b7ee940127766d99f669683f0edda1733e05f.png)
