DesignScript Flatten not working in Function

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 (19.6 KB)

1 Like

Hi @Mepdot

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

Here is the edited function:

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:

2 Likes