WRANGLE THAT DATA: DYNAMO FILTRATION AND SORTING

April 6th, 2017 Posted by computation, Download, Dynamo, Tools 0 comments on “WRANGLE THAT DATA: DYNAMO FILTRATION AND SORTING”

List Management is key to leveraging power in Dynamo. This blog post will explore a series of options to Filter and Sort using out-of-the-box nodes, designscript and python workflows.

This list is not exhaustive, nor does it cover the myriad of different Collectors and Custom Filtration Nodes present within other packages, but it does provide some insight into how filtration and sorting can be approached.

All of the workflow approaches have been annotated within the display graphic as well as the accompanying scripts – both available for download at the bottom of this post.

Dynamo 1.2.1 was used for the generation of all available Scripts and Images.

Nodal

List.Filter requires a condition to run. In some ways, it’s the shorthand version of List.FilterByBoolMask, but doesn’t quite have as much power due to the Function object limitation. However, it is fast and powerful when a Function Condition is a suitable mask input.

List.FilterByBoolMask simply requires a matching list of true and false values that has a count value equal to the input list. It gives us a huge amount of power to create this list division based on any number of criteria. As such, it’s one of the most used filtration nodes and is an inordinately flexible node that forms part of most workflows.

RemoveIfNot is a BuiltIn Dynamo node that will filter based off type criteria. It’s useful for quickly splitting geometry based operations, but doesn’t work very well when trying to differentiate between strings, doubles, integers and other core object types.

SetDifference will take two lists and simply give you what doesn’t pair up between the two. It’s a very versatile node that works on almost all data types.

The Formula node should be familiar to most users of Revit and builders of Families in Revit: It uses the same formatting (NCalc). It’s a quick, easy and familiar way to quickly filter data.

The GetKeys method is very useful for paring disparate lists of data as it does a cross-product laced match process. Useful to pair data between jumbled lists such as an Excel Sheet list and the internal Revit one.

The GroupByFunction node will use a function input (Similar to the List.Filter) to group a list of objects. The SortByFunction node will do the same, but for sorting rather than grouping.

The GroupByKey node will use a key value to group a list of objects. The key can be anything so long as each key matches the item you want to Group. The SortByKey node will do the same, but for sorting rather than grouping.

Function.Compose will allow you to collate multiple functions together. It works by pulling data from the first blank input (Appropriating the input from your list further down the graph) and then iterating downwards, sequentially, on that data as it’s queried or actioned by each node plugged into the Function.Compose node: func0 runs before func1, func1 runs on the data pushed from func0, func2 runs on the data pushed from func1 and so on.

DesignScript

We explore only two options in DesignScript: Single and Multi-tiered List.FilterByBoolMask options. Almost all of the previously explored nodes above are able to be queried in DesignScript so go explore – have fun with it! It’s not as scary as it looks ?

Calling a single list output List.FilterByBoolMask in Designscript is the same as within the node – it requires a true/false boolean list input that matches count values. In this example, we explore how we can pull the data out from a single tiered list using the inherent dictionary option that each output is associated with.

The only difference between our single approach and the Multi-Tier List.FilterByBoolMask method is the call value at the end. To pull a multi-tiered list we need to use a different Get option.

Python

The final option we explore is Python. Here we create a custom Python node with a few caveats: Normally, we would query the data type coming in (In our example, a float value won’t work) in order to make sure our node is robust enough to parse multiple data types or parse out a failure message stating why it won’t work. So, while we are not really following best practise it illustrates how to begin thinking about using Python in the Dynamo environment.

This node is simply supposed to be an introduction into one way you could approach filtration within Python rather than the quote-unquote best way.

Final Thoughts

There are many ways to approach the filtration and sorting of data within Dynamo and there is no right answer – each method has particular use cases and will be appropriate within its own context. The purpose of this post was to illustrate a few options on how to explore the processes in Dynamo.

If you have any other awesome methods not mentioned then please do get in touch – we’re always willing to learn, re-learn and un-learn if need be!

NOTE: Some of these examples are simply that – examples. They highlight in a simplistic sense how to push and pull data through these nodes rather than necessarily being the most efficient or applicable method.

Tags: , , , , , ,

No comments yet. You should be kind and add one!

Leave a Reply

Your email address will not be published.This is a required field!

<small>You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:<br> <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>