# FilterByBoolMask output keep list structure and sorting

**URL:** <https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734>\
**Category:** Lists-Logic\
**Created:** [August 9, 2023, 10:13am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734 "2023-08-09T10:13:59Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 9, 2023, 10:13am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/1 "2023-08-09T10:13:59Z")

</div>

Hi,

Anyone that cant give me some advice how to keep list structure and sorting, see image below.

Thanks!

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/9/e90ffa074f362c36fae2157d461bd7354e05cde5.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [August 9, 2023, 10:41am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/2 "2023-08-09T10:41:51Z")

</div>

@BIM_Mrbrango .

instead of using filters you can also use groupByKey and than indexing your Items…

That would be my first idea…

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/6/e64dbdc73c8bf287b48d47729c1ad6231a2f4935.png)

KR

Andreas

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 9, 2023, 11:53am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/3 "2023-08-09T11:53:40Z")

</div>

OK, do you think I shall change filterbool in the begining (Red circle) or at the end ?  
I dont see how this should help me get the list structur that I want, but will give it a try.

Thanks @Draxl_Andreas

By the way, du you also have a solution to this list logic.  
Everthing filters right until the end, why?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/e/4ebe2cf6887c48252b312e08ce82108361dc76e9.png)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [August 9, 2023, 3:44pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/4 "2023-08-09T15:44:07Z")

</div>

Can you explain what you’re actually trying to do here? Your first image is illegible and it’s a little confusing. List structure and sorting won’t change unless you do something to change it.

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 8:49am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/5 "2023-08-10T08:49:24Z")

</div>

Hi @Nick_Boyts,

Sorry that the picture is not fully legible, I initially thought that it did not need to be shown as the question was only about how I should be able to preserve the structure.

Just as you write, the structure of the list has been changed, now I want to try to recover the structure of the rest of the nodes in the port out.

As you can see from the Image from first post (I filter out everything except 2 points that I process for creating Tee. The out port I deal with vertical pipes that dont have horizontal pipes, these other gaps might have had a valve of some sort that need to be handled)

Picture below does not work properly, because of the other issue that I ran into when adding one more pipe branch as mentiond below.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/0/80f61638352345bc2f6752c63b8625df834dbbfd.png)

Now I want to see if it is possible to recover the other nodes in the OUT and keep the same structure without having to do the same processing again, which feels unnecessary if there is a better way to divide what should go to port IN and port OUT.

* * *

Picture number 2 wich I updated in this post.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/a/8a089c438e69df09741fb7cc1d98b5d85ca1af70.png)

Before I flatten the list, the information comes from MepOver’s Element.Connectors.

I use List.GroupByFunction to group all y-axes, which appears in the image, all values ​​are grouped correctly.

But if you look at the final product, I have 10 nodes out, but they are not the nodes that were grouped in List.GroupByFunction.

What I do know is that I created another pipe branch in the picture below labeled 2, when I only had pipe branch labeled 1 there were no problems with the end result.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/a/da57d052b44e51a0b3025918453a7bada56ed4b8.jpeg)

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [August 10, 2023, 8:57am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/6 "2023-08-10T08:57:22Z")

</div>

Hi probably i dont understand, but is you goal connect these pipes with elbow and tee fitting ??

---

<div class="post-metadata">

**Author:** ![pyXam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/pyxam/32/163009_2.png) [@pyXam](https://forum.dynamobim.com/u/pyXam)\
**Post date:** [August 10, 2023, 9:07am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/7 "2023-08-10T09:07:04Z")

</div>

Im confused in which way you want to restructure the end result?

If the number of items in both the unfiltered and filtered lists is the same, then you can use this method…

> [@Change list structure to match another list structure](https://forum.dynamobim.com/t/change-list-structure-to-match-another-list-structure/27451/9):
>
> Might be late to the party but thought it would be a fun test of recursive functions in python: # Enable Python support and load DesignScript library import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import \* def recCount(\_lists,c): for \_list in \_lists: if isinstance(\_list,list): c = recCount(\_list,c) else: c += 1 return c def recMatch(\_list,\_matches,\_out,c): for \_match in \_matches: if isinstance(\_match,list): outTemp, c = recMatch…

If it is not, then without a better explanation (by that i mean, dumb it down a bit, simplify what you are asking) then i am so confused.

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 9:40am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/8 "2023-08-10T09:40:10Z")

</div>

Hi @sovitek  
I didn’t know I was so unclear with explanatory text and pictures.

But I want to see if there is a solution to keep the same structure from one list to another.

When it comes to tee’s, I have it figured out.

I want to keep the list structure for the group **Vertical pipes that dont have horizontal pipes**.

This is to avoid building the same structure again, but then minus the nodes that have moved on via the IN port

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/b/6ba275b29a0dfebcaa3bfcc483742ac48a8ceef4.png)

---

<div class="post-metadata">

**Author:** ![pyXam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/pyxam/32/163009_2.png) [@pyXam](https://forum.dynamobim.com/u/pyXam)\
**Post date:** [August 10, 2023, 10:00am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/9 "2023-08-10T10:00:00Z")

</div>

So what you are trying to do is…your original list, minus the items on the second list?

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 11:07am UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/10 "2023-08-10T11:07:39Z")

</div>

YES, thats correct

---

<div class="post-metadata">

**Author:** ![1bitBoolean](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/1bitboolean/32/165603_2.png) [@1bitBoolean](https://forum.dynamobim.com/u/1bitBoolean)\
**Post date:** [August 10, 2023, 12:03pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/11 "2023-08-10T12:03:50Z")

</div>

Correct me if I’m wrong. Can’t you just… hit “use levels” and “keep list structure” on boolMask “list” input?  
Can’t test rn but could have sworn I have used it before for advanced filtering.

EDIT:  
Tested - you absolutely can:

 ![Screenshot_3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/7/d724b54620d3f20ac8a1d72a02dfea4606cba160.png)

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 12:18pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/12 "2023-08-10T12:18:39Z")

</div>

Great, I’ll try it later and mark this as answer

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [August 10, 2023, 1:53pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/13 "2023-08-10T13:53:09Z")

</div>

As I mentioned earlier, structure and sorting only change if you do something to change them, which you did. When you group the connector locations based on the Y coordinate you’ve restructured your data. The list of grouped points no longer matches the list of connectors.

You’re probably better off restructuring the connectors to match your data. You can use `GroupByKey` instead of `GroupByFunction` to group the connectors based on their Y coordinates (keys). Then you’ll be dealing with the connectors directly.

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 2:10pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/14 "2023-08-10T14:10:58Z")

</div>

Hi Nick,

Thanks, I’ll give it a try later when I’m on the computer again

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 3:17pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/15 "2023-08-10T15:17:29Z")

</div>

Super Thanks @1bitBoolean !

This is the end result, exacly what I wanted!!  
Now I can continue with OUT nodes in the same exacly like they came in.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/8/b85889655dbd92cdfacc5c8f1a73818f446e96c9.png)

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 3:54pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/16 "2023-08-10T15:54:43Z")

</div>

Hi again @Nick_Boyts,

I change to GroupByKey but the same result remains, even closed down dynamo and revit between dynamo runs to see result, its the same.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f207a88b9f707e28e8940407e764da285207c5f8.png)

If I remove the upper pipebranch everything work great. But when I add it again the “error occur”.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/2/e2a721ad2e14e609b6820d764615a1ae22e1eb52.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/0/80b1db7847784271c5344c6af5b68c5586dd9cd2.png)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [August 10, 2023, 3:59pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/17 "2023-08-10T15:59:21Z")

</div>

You want to group the _connectors_ not the points. Then you’ll be dealing with the connectors themselves and won’t have to worry about matching the original list structure. You still use the connector location and Y coordinate as the key to group by, but you feed the list of connectors.

---

<div class="post-metadata">

**Author:** ![BIM\_Mrbrango](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BIM\_Mrbrango](https://forum.dynamobim.com/u/BIM_Mrbrango)\
**Post date:** [August 10, 2023, 4:51pm UTC](https://forum.dynamobim.com/t/filterbyboolmask-output-keep-list-structure-and-sorting/92734/18 "2023-08-10T16:51:53Z")

</div>

Hi @Nick_Boyts,

You are of course right, why didn’t I see this….

I knew it all along but wanted to check if you saw the error 😉

I even added a 3 pipe branch and it works great.  
Again, many thanks!!!

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/d/6d35d8da1bb5627aaf314a835fa99b581126506d.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/b/9bb48c0a292a43566f23fd3627f7a0ba9faeb8bf.png)
