Test result = true/false > take that index (sublist) in the true/false list

Hello guys,

So, I’m doing a routine for positioning plumbing fixtures tags and I’m trying to use the host (wall) orientation to define where these tags should be positioned. (I created horizontal and vertical points). I need to make sure that:
when the test result = true, take that index (sublist) in the true list.
when the test result = false, take that index (sublist) in the false list.

I’ve tested with If, Logic If, Scope If and List.ReplaceItemAtIndex, but I need that if all results are true or all are false I still have an output list


I think you’re making this more complicated than it needs to be. It’s always best to have the same number of inputs when dealing with If statements. Your conditional statement should look like this:

v.X == 0 ? SortedListTrue : SortedListFalse

This checks each vector individually and returns its respective value at the same index for either the SortedListTrue or SortedListFalse lists.

If you’re looking at the entire list of vectors at once and need a single pass/fail you would use indices to select your sublist.

SelectionList = [SortedListTrue, SortedListFalse];
i = AllTrue ? 0 : 1;
FinalSelection = SelectionList[i];

This way you’re creating a list of possible outcomes and using a conditional statement to return the index of the outcome you want. Then you just get the item at that index. This allows you to avoid the issue with mismatched inputs.

1 Like

Hello @Nick_Boyts
Thanks for the quick reply … Yeah, I know It shouldn’t be so difficult, but I’m still doing baby steps with non-visual Programmation :sweat_smile:

Tried this way but the node gives me “Warning: Null value cannot be cast to Int32”

This one Works but It gives me just the first value of each list (and I need all the values inside the list 0 and 1). I think I need to change the lacing of the Code Block, right?

You can ignore the first option. I wasn’t sure what your inputs looked like so I gave you both options. The first option would be for if you had a vector corresponding with each point, but you do not.

AllTrue is just the name of the variable I created, you’re not actually calling it in the Code Block. It should be the input from the List.AllTrue node. I should have mentioned that. I knew that might be a little confusing the way I wrote it.

I’m still doing something wrong, I get both lists in the end, But I should have just 46 points as output of the code block :confused:

Not sure if I’m following, but I’ll give it a shot.

You could place another List.AllTrue after your first List.AllTrue with a List at Level 1. This should return one bool value which should then make the Code Block in your last post function correctly.

Or if not wanting a code block, you could return back to your original post where you marked up a “Test, True, False”, there then after adding a second List.AllTrue, you would get on bool value and should be able to use a traditional If node.

Maybe… :slight_smile:

List.AllTrue is returning two values so you’re getting two lists. If you’re checking all wall vectors, regardless of list structure, then you’ll want to flatten your list of vectors before using List.AllTrue. Right now you’re checking each sublist (of a single item) and getting two booleans.

I don’t know if I’m understanding it properly, but if I understanding it right: The problem is that not all elements have a host, so I can’t have a vector for each element. It seems to me that the best possibility is to have a list with true or false indicating the orientation of each room (and in reality the sublists with dots represent the rooms) So if a room is horizontal I want all those points to be positioned horizontally … and the reverse if the room is vertical …

I’m sorry, maybe I didn’t explain it clearly

This actually made Dynamo crash :expressionless: (no Idea why), but thanks anyway

Uhuull I think I got It! Thanks a lot everyone (Yeah, maybe not the most insightful method … but it works…)

1 Like