Difference between IF then code block

I hope i am in the correct category.
I made a little code block to help me swtich between 2 sources of element lists. This is for debugging purposes do i do not have to run the code on the whole Revit project, but on a selected portion of it. And i can switch back and forth with flip of a switch. But since i had some “null” issues coming out of my Mux-1, i looked around and found out another way to do it. but I really want to know what was wrong with the first one i wrote (Mux-1)?
if you look in attached, you see that one generates 15 elements while the other just 11. Moreover, depending on my selection , sometimes Mux-1 sends out “null"s and i get the " Warning: Internal error, please report: Dereferencing a non-pointer” error.
So what is the difference between the code in the Mux-1 and Mux-2?

You can check this post:

Problem might be lengths of your lists.

I did look at that link at some point. but i don’t think this is what i have.
but either case, i happy with Mux-2, it does what i want it to do. my question was how is it different than Mux-1? besides the syntax, is there logically anything different?

If statements only work with input lists of the same length. The conditional inputs for the Mux-2 are the same length.

The other list from the project would be about 4000 elements so i know the issue of the shortest list is not at play here.
So, the same list is passed to both Muxes. yet Mux-1 shows only 11 out of the 15 that Mux-2 shows. why were the other 4 left out? that is what i am not able to grasp.

I see. Your list of elements from family types doesn’t look flatten. Do you happen to have 11 sublists?

ok, i noticed that earlier, when i had the error, that nulls was affecting the if statement.
so what you are telling me effectively, that in Mux-1, since i used and if statement, i fell in that trap. But in Mux-2 there is no if statement, but an “assignment” of which list it the output, i do not fall in that trap.
correct?
in which case it makes since to use this method over the if statement method, when the logic allows it.

I think we can safely ignore the output from the Family types block since it is not used here… it happened to be here when i noticed that my outputs from either Mux are different for the same input that is coming out of the “Select Model Element” block. that output had 15 elements in it (irrespective of what the “family types …” block had. And since that list was fed to both Muxes, the output should be the same… but i think you awakened to the structure of my code. Mux-1 used and if. Mux-2 did not.

That was my thought originally, but usually the null issue is with the inputs and not the outputs. I still think it’s list length but it’s hard to tell since I can’t see your other inputs.

I’m talking about the All Elements of Family Type+ node. If you’re feeding it a list of types then you’ll get a sublist of elements for each type. Can you show a preview of the output?

Hi Nick,
i ws talking about that node as well…
i deleted the previous environment and had to recreate it sorry…

so here it is choosing the project elements, and not the Selected elements. so there are 4K + elements.

But what i did here is i removed that node and put a simple list and toggled the slider and here are the outputs:

My interest was in why the list is shorter for slider=1…
So initially i thought since i have 4K+ element on L0, then the “if statement” issue could not be at play here. But after i replaced that node with a simple list node, one with 0…10 and another 0…20, i found out that the “if statement” issue was still at play here. But why was it stuck at 11 elements, i guess because i must have used it before i reconnected the project node.

it wont let me add more one image at a time… sorry…

My point is that your list structure was not the same. An If statement always returns the length of the shortest list. You may have over 4000 pipe elements, but the list you’re using is 11 sublists (1 for each family type). That’s also why you’re getting the null values for that selection - the condition is trying to run on a list instead of a singleton.

In my example you can see that I have 3 sublists of communication device types. That’s my shortest list so I only get 3 objects returned. The selected elements return correctly because the condition is running on each element. The list of types fails (null) because the condition is running on the sublist and not the element.

All you need to do is flatten your lists.

HI Nick,

thanks for sticking with me on this.
i just checked my list of 4K elements and you are right, it is a list of Lists… with count = 11… Surprise!!!

so i learned another thing here… thanks.

what is the best way to flatten it?

No problem. There’s a Flatten node that will do exactly that.