Empty List flatten

Hi all,

I am trying to export some model data to Excel. To keep up with the formatting/rules, I have to make sure that no data without a list level gets through as it causes a warning.
While ensuring this, I came across some empty lists that flattens out completely without having at least one list level. Any suggestion?


you want to drop out empty lists?

1 Like

It’s hard to tell what you’re after. Everything you’ve showed is as expected. In your first example, a list of one item still flattens to a list of one item. In your second example, an empty list on its own may not show the corresponding list levels (because there are no items to hold them) but they are still there.

I’m not sure how true the following is, but I think the reason for the latter is because the dimension of the empty list is basically unknown without any additional structure. An EmptyList is both a single item on its own and an n-dimensional list. Without other items in the list to determine the final structure, the empty lists are just non-descript placeholders. Schrödinger’s List, if you will.

3 Likes

@Nick_Boyts, I’m trying to export my data to excel and that’s why I am looking to eliminate any possible exceptions which may mess up the output. In this case, an Empty List without any list level cause issues when I add multiple inputs in List.Create > List.Transpose > Data.ExportExcel. I hope you understand my point.

@Draxl_Andreas, I want to export data to Excel. Excel node only expects data in a list format NOT Int64 or string.
In some cases, input data can be (see image input - Unpinned Revit Files)

  • empty
  • one value without any list
  • one value with a list
  • a list of values

The first two require the data to be modified in order to maintain the export excel. This is the reason why I want a quick way to resolve such exceptions. Because I think my current way of dealing with exceptions is quite cumbersome. I hope you understand my point.

@theshysnail check this:

It will deal with all of your outputs to be list of lists, for the Empty List, try to make it a string, apply the above to that string (list of list), then feed it to Excel.

1 Like

@Elie.Trad

What do I need to do with the Empty list, again?

On the one hand, I can simply check if it’s an Empty List, then only do List.Create on its, skipping the List.Flatten node. But on the other hand, it does not seem very efficient to use this much chunk of nodes for each and every bit of data I want to export to excel.

@theshysnail try this:

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

input = IN[0]

end = []	

for i in input:
	if isinstance(i, list) and not i or i == None:
		i = "it's Empty!"
		result = [i]
	elif isinstance(i, list):
		result = i
	else:
		result = [i]
	end.append(result)
	
OUT = end
1 Like

You still haven’t said (or better yet, shown) exactly what you want to happen. Do you want EmptyLists removed? Converted to empty cells? Once we have this information we can look at options like filtering, list cleaning, or replacing items.

1 Like

yes i dont understand the question or goal here…

It does not seem to work for me.

1 Like

aha now i understand :wink: …another way could be this one here from clockwork…

2 Likes

@Nick_Boyts @sovitek

The empty lists as you can see in this image above causes problem with exported data in Excel.

Without any empty list, exported excel looks like this. Separate column for each corresponding data.

If there is/are any empty list in the data to be exported, excel keeps overwriting all the data in one column only. The problem further deteriorates if you have multiple excel tabs.

@sovitek Thanks for understanding the problem. :relieved:

This custom node packs a lot of stuff inside it. I’d be hesitant to use this many nodes each time a bit of data is being fed into Excel. There will be dozens of copies of these sets of nodes in my graphs.

I have another solution containing only OOTB set of nodes here which I hinted previously that I can use in all of such places. But I’m more interested in a quick and elegant solution.

yeps many ways :wink:

Yeah. I’ll prefer if someone can condense this “exception-handling” mess of mine into a single and simple python node.

Oh… this is also failing. ;(

think its becourse your false input is a empty list…you could try scope if from clockwork…

Would this help?

def rtnLst (lst:var[]..[])
{
	return [Imperative]
	{
		ls = List.Flatten(lst,-1);
		if (List.Count(ls)<1)
			return [[]];
		else
			return ls;
	}
};
4 Likes