Filter Transposed List to have only items with value

Hi everyone,

I really hope someone could help me out! I am not pro at Dynamo, and I got stuck.

I have this list I created which is composing of 2 parameters which title blocks in my project have.
The parameter is yes/no, so the result is either 0 or 1

There is a few of the title blocks which do not contain this parameter, therefor the index is empty.

I would like to filter out only the title blocks (so elements) together with the index which contains either 0 or 1 as a value and remove the empty values.

List.Clean does not work for some reason.

My final goal is to have all the title blocks which have this parameter, so I can change the parameter to always be 0 or always be 1.

I unfortunately can’t upload the script because of authorization, but I am attaching a screenshot

@BIM00 ,

the issue is that , there are booleans in default mode… so you have to activate them f.e. set to


# 🏗️ parameter boolean

x = true
x = 1

y = false
y = 0

# z = default
# does not exist as data value in revit

Hi Draxl,
thanks so much for a fast reply!

I get that they are 0s and 1s, but I would like to remove the elements which don’t contain this specific parameter, and have only the ones that do

Out of misery, I tried connecting some random nodes :sweat_smile: , and this randomly worked

I am really curious how would I do this the ‘right way’

I think you’re better off not transposing the data. If you want to filter the elements based on their values then you’re better off with two separate lists. Then you can check for 0 or 1 and use FilterByBoolMask to filter the elements directly based on the results.

@BIM00

just set a codeblock or a node to remove nulls


# ❌remove nulls

_input == null ? false : true

you can filter your elements.

Hi Nick:)

I wanted to transpose because I wanted to see which title block has the parameter and which doesn’t.
But I agree, it would probably be easier just to do it in separate sheets

Since I have all 1,0 and empty value, how would you create a mask for List.FilterByBoolMask? So I would get only 1s and 0s?

You could either look for the blank (x == "") or for the 0s and 1s (x == 0 || x == 1).

About the List.Clean node.

To my knowledge / in my experience
there are packages which have a similar node
but do a better job than OOTB one.

Can you give an example?

I will when i get behind a PC again.
But i had different result using similar nodes
from packages.
Maybe the input had something to do
with it…

Also i might need to find a script where
the OOTB node didn’t work for me.
Don’t know if i can replicate an issue
with the OOTB one.

Also not sure what the OOTB is supposed to do?
Or what the difference is with the ones from packages? Why are there custom List.Clean nodes if the OOTB (should) work(s)?
Why doesn’t the node work for OP?

Looks like the circled items are empty strings, not null values.

My recollection is that originally without the ability to use ListLevels it was difficult to manage removing content without removing list structure. That was… 7 years ago now? (side note: I am old now). There were also some which allowed replacing empty strings and null data with an alternative data type, which in my opinion is t cleaning the list but replacing data.

There’s a lot of misunderstanding around what the List.Clean node does and how it works (i.e. preserveIndices). Most people try to use List.Clean to remove bad data or structure that they don’t understand. They end up using a custom node that does what they want without understanding what they’re actually doing.

In this case, there’s nothing in the original list to clean. There are no null values and there are no empty lists out of alignment. List.Clean doesn’t just remove empty strings or sublists containing unwanted values.

1 Like

I think you hit the nail on the head with this

Though i don’t know what you mean by “bad data”.

But i also think the term empty can be a little confusing to some people.
Like empty does not equal blank.


OOTB


GeniusLoci

1 Like

Different nodes for different tasks with these two nodes. I am not sure when I would want to remove empty strings from a list of data though - perhaps the original poster has a use case though.

hm I am not sure if I am doing something wrong, but I keep getting the same

I had to use L3 because at L1 and L2 it hasn’t done anything

And I get the same if I use the first solution you mentioned

did you mean something like this? Because I would still get the same result


@BIM00

oh, right, thank you! But I still get the wrong result

In the List.FilterByBoolMask out list is empty and in list has the same amount of title blocks as at the beginning

@BIM00

mybe set the codeblock to

# variation
_input == None ? false : true
_input == "" ?

or you write a python code

python :rocket:

values = IN[0]

collection = []

for i in values:
    if i == None:
        collection.append(false)
    elif i == "":
        collection.append(false)
    elif i == Null:
        collection.append(false)
    else:
        collection.append(true)


OUT = collection

There is a few of the title blocks which do not contain this parameter, therefor the index is empty.

Is it not better to just filter those out first?

Also shouldn’t this do the trick for the empty values?

Also this should work (an alternative).
If needed true can be 1 and false can be 0.

2 Likes