Remove null values in Code Blocks


I’m learning to create functions in Code Blocks. The function is based on the If Equal Return Index custom node, it works but i don’t want the null values. Any idea?..



You can perform a function to remove null values, but I think the best way to remedy the situation is to avoid creating any null values in the first place.

In your function, the null values are created because you’re using the match index for the returned list’s index as well and you end up with a list that has nothing (or null) in indexes 0 and 1.

We can solve this in a few ways. One solution is to just add a variable for the index of the return list,another one would be to add an empty list when there are no matches and then flatten the empty lists away:



Oh , I had no idea. I 'm trying to understand your explanation, meanwhile I solved it this way:


Thanks for your time.


That’s a nice solution too. :slight_smile:

Probably I am quite late responding here, but anyway…

You can use directly the built in function RemoveNulls

(I don’t know why it is not listed in the library and not available as node)


Thanks. :smiley:


Great solution.

Where i can find more advanced information about DesignScript?



DS functions, like RemoveNulls, not appearing in the library are quite rare and unusual. I know RemoveNulls from the time of DesignScript for Autocad. So you can find information about it in the plugin reference documentation (for autocad 2013 and 2014 if I remember correctly). But the language has changed quite a bit (mostly for better) so it can be very confusing.I wouldn’t bother.

Anyway, you have already in the 8.1 daily builds the new method “List.Clean”. So no need to use “hidden” built in functions like RemoveNulls

Thanks, Eduardo.

I used this method to filter out Null