Input list with a null as the first item causes many nodes to fail - workarounds?


I’m building a Dynamo tool to number Doors and Windows according to their ToRoom and FromRoom parameters. I’ve just solved a major roadblock outlined here (Order of execution problem: changing same parameter twice) but now I’m running into an even more alarming bug that’s potentially going to cause lots of trouble.

Basically, it’s this old issue:

If a Revit node takes a List as an input, and the FIRST item in the List is a null, the execution of the entire node fails. I understand this is because the data type of the node input is determined by the first item, in case of mixed-type Lists. (as a sidenote: I don’t think this is a wise approach, but the datatype should be determinable by the author of the script. If you have mixed lists, you probably don’t know the order of the list items beforehand either.)

In my Dynamo definition there’s a List of Doors (every door in the active project), and 2 corresponding Lists of Rooms (the FromRoom instance of each Door, and the ToRoom instance of each Door). The problem is that the Room lists might be incomplete, in case some Door is an exterior door and has no Room on the other side. So

  1. there will be nulls in the Room list
  2. there’s no way of knowing where in the list these nulls are, because the doors are retrieved automatically, so…
  3. …there might be a null as the FIRST item in the list - which causes the script to fail
  4. I need to keep the Door list and the Room lists as being the same length in order to input the Room properties into the corresponding door, so List.Clean is out of the question.

I’ve just fixed one problem with Nulls in the list using the Clockwork node List.ReplaceNull - but in that case the List datatype was a String which is easy. Now I’d essentially need to replace the null entries in the Room list with Room objects to prevent the next node from failing. Is this possible? How can I create a new Room and then delete it after I no longer need it?

A workaround would be to add a dummy legal/acceptable value to the top of all lists.
Then remove the first value from all lists after they are processed.

Hi Vikram,

That’s what I thought. But I’m finding it difficult to create a “dummy” Room or Door object - is that even possible?

My current solution is testing whether the first item in the FromRoom or ToRoom lists is a null, and replacing that with the first item in a list of all Rooms in the active project… It’s quick and dirty, but it works. The nodes no longer fail but there’s the risk that one of the doors in the project (the first door that was created) shows a random room (the first room created) in its ToRoom or FromRoom parameter when it’s supposed to show a blank number. It’s not too bad though.

I also created a routine that removes that wrong room info from the first door in the list, in case the FromRoom or ToRoom of that door was null. For some reason this only works half of the time though.

Just insert one of the valid members from your list back into itself, then remove it as per @Vikram_Subbaiah suggestion

Hmm, that might actually work. I’ll try inserting the first Room in the project to the beginning of both FromRoom and ToRoom lists - regardless if their first member is a null or not - and then just fill the Doors with parameters starting from the SECOND member of each Room list.

I’ll report back if it works. Thanks! :slight_smile:

Yep, that solution seems to have worked! I can’t use a valid member from the list itself, since I initially have no knowledge of which members in the list are nulls and which are valid. Instead I added the first member of a new List of Rooms in the project, proceeded to extract the room numbers and names in another list, then dropped the first item of the room number and room name lists to feed that data in proper order back into the doors in my project.

Thanks everyone for your help!

1 Like