And, Or and Xor

Recently I was busy with getting some info out of a Revit model and I was using Clockwork’s node Windows.Rooms. The node works fine but understanable gives nulls if a window does not have a to or from room.

For the thing I need to do next with these windows I would like to split the windows in four different lists.

  • A list with windows that have To and From rooms value.
  • A list with windows that only have To rooms value.
  • A list with windows that only have From rooms value.
  • A list with windows that have NO To and From rooms value.

If I add the node Object.IsNull I get some nice Booleans. But then I run into this issue that the OOTB nodes “And” and “Or” don’t take lists. I have been trying to use these nodes in combination with something like a Function.Apply but without any success.

So then I decided to make a python nodes to see if I can deal with these lists. I am pretty sure that the nodes I am creating can be combined into a more elegant node but learning things go with small steps, and I need these in-between steps to get there.

Let’s first find the rooms that have a To and From Value (that is NOT null)

  • IN[0] will get the values From Values.
  • IN[1] will get the To Values.
  • IN[2] will get the windows.

This means that for the Python script, I have to iterate over three lists at the same time. The zip function in Python allows me to do that.

https://www.w3schools.com/python/ref_func_zip.asp

 for f,s,e in zip(first,second,elem):
    if f is not None and s is not None:
        Results.append(e)

The first line iterates over three lists. Relevant here is that the data from the three lists are in the same order and preferable length!

The second line takes the first item (f) of the “First” list and checks if the value is Null (None), and this gives a Boolean (true or false). The Second condition on that line works the same. This gives a Boolean (true or false). If both of the conditions, on the second line, are true, then the item from the list of windows is put in the Results list. If any of the two conditions is true, then that window does not get passed into the Results list.

The inverse of this script is easy to make if you take from the previous script and take the “not” out then you have a script that finds all the windows which have values for the ToRoom and FromRoom.

 for f,s,e in zip(first,second,elem):
    if f is None and s is None:
        Results.append(e)

The last condition I needed turned out to be a bit more tricky than I anticipated. Because now, I wanted a script that could find windows that only has a ToRoom or a FromRoom. I started with the code below. I replace the “And” condition for “Or” and then my learning moment presented itself.

 for f,s,e in zip(first,second,elem):
     if f is None or s is None:
         Results.append(e) 

I thought I was going to get four windows, but I got six. Of course, the windows that have no ToRoom or FromRoom also comply with the condition… Meaning I need to filter those out first. So I added that first and I needed to put those windows in a separate list I called temp. There is probably a more elegant way to do that, but this worked for me now. So when a window does not pass the “if” part then it moves to the else part.

 for f,s,e in zip(first,second,elem):
    if f is not None and s is not None:
        temp.append(e)
    else
        if f is not None or s is not None:
            Results.append(e)

Now I have all windows for which either the ToRoom or FromRoom is None and not Both. All the windows that have both a ToRoom or FromRoom are also excluded.

And, Or and Xor

One thought on “And, Or and Xor

  • 2020-03-08 at 00:28
    Permalink

    Great script. I usually have a “dummy” Room named Exterior which is nothing more than Room Separation Lines that enclose all my Rooms.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: