Remove Empty List Preserving Hierarchy


#1


Hi guys I wanna remove the empty lists but want to have my hierachy in the list of list. So basically in this context I want a output list like

  1. Nurbscurve
  2. Nurbscurve
  3. Emptylist

Hope I make myself clear. Help me out. :slight_smile:


#2

Try List.Clean with the boolean set to true:
http://dictionary.dynamobim.com/#/Core/List/Action/Clean
See also:


I can’t find any illustration for List.Clean with boolean set to true. Please send a screenshot if you used it successfully so we can reuse it as a reference for similar issues.


#3

I tried it before… And worked with the levels as well. Doesn’t seem to work


#4

Try playing with the node levels to see if it helps:
http://dynamoprimer.com/en/06_Designing-with-Lists/6-3_lists-of-lists.html
http://dynamobim.org/introducing-listlevel-working-with-lists-made-easier/


#5

Hi Yna, I do understand how levels work. And I have been playing with the levels and Preserving Hierarchy for a few hours already. The issue is with Empty Lists. When I ask any of these nodes to remove the empty lists… they just remove it through n through.
try it out. You will understand what I mean. Have been using Lists and Levels in Lists for quite sometime now.


#6

Sorry I can’t right now. If no one else does, I’ll come back in a few hours on this topic…


#7

Thanks for the support Yna :slight_smile:


#8

Hi @Amrit_Banerjee

Just use “Flatten” node:


#9

Hi Kulkul,
The issue is I won’t have a nurbscurve in every list of lists. Sometimes its all Empty list (when there is no Geometry Intersect in my case).So dynamo entirely remove the Entire Index without a nurbscurve. I want to maintain the index and list it as null or a single empty list when it doesnt find a nurbscurve. Hope that makes it clear. Check the image.


#10

DanEdu.List.Replace should respond to what you describe:


If not, please send a screenshot showing your initial and expected lists :slight_smile:


#11

@Amrit_Banerjee Note that Lacing is Longest in the examples below


#12

Hi Yna,
Yes this was what I was doing yesterday as a workaround. But @Vikram_Subbaiah’s Method works like a charm :smiley:


#13

Great, you will fine in the Primer more information about lacing if needed:
http://dynamoprimer.com/en/03_Anatomy-of-a-Dynamo-Definition/3-1_dynamo_nodes.html
If you need to preserve the complete structure of the list, you can do it like so:


#14

Hi,
I have a similar list problem, but my list only has one level. Is there a way to remove or make Dynamo ignore the “Empty List” values and still preserve the list hierarchy?

What I’m trying to achieve with my script is to check for views placed on sheets and to find views which do not already have the sheet number as a prefix in the view name, and then rename these. The Empty List value shows up for views which already have the sheet number as a prefix and therefor shouldn’t be renamed.

I’ve tried using the List.clean and List.Replace from DanEDU

Any help deeply appreciated!


#15

Until someone who knows how to do this in code blocks comes along, I quickly wrote a python script that should fix it? I am on my way out of the office and didn’t have time to test, but see if it works.

Replaces the SetParameterByName node, same inputs. Python code is:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

#The inputs to this node will be stored as a list in the IN variables.
elements = IN[0]
paramName = IN[1]
values = IN[2]

for i in range(len(values)):
	if hasattr(values[i], '__iter__'):
		for j in range(len(values[i])):
			elements[i][j].SetParameterByName(paramName,values[i][j])
	else:
		continue
#Assign your output to the OUT variable.
OUT = elements

Let me know if there are any problems.