List replace by condition to Empty List Item

You could try this workaround
Not very clean though.

def emp (a:var[]..[])
{
	b = [Imperative]
	{
		for (i in a)
		{
			if (i==[])
			{
				return null;
			}
			else
			{
				return i;
			}
		}
	}
	return b == null ? "xx" : b;
};
2 Likes

perfect, empty to Null to variable as well

many thanks for the loads of possible solutions, finally I take this like the best option. I modified a script sample of @c.poupin of other post with similar questions to get this solution as well.

the designscript with definition in external code of @Vikram_Subbaiah gets warning telling that “emp” is not defined but it is, although I get result correct but warning and dynamo freezing, not responding for a while, in comparison the python code runs instantly without waiting response, quite tiny in the graph as well.

this kind of answer is not acceptable on a forum where you are offered help, and avoid create multiple topics with same questions

4 Likes

I tried to delete some braces but the code block gets a red warning, expecting the brace removed, I am not familiar writting code as this type, many thanks for your solution, it works well.

If you want to learn DesignScript, there is lots to download.

DesignScriptDocumentation.pdf (705.5 KB)
designscript-final.pdf (1.5 MB)
DesignScriptGuideV2.1.pdf (343.2 KB)

7 Likes