Oops...

This website is made for modern browsers. You are seeing this, because your browser is missing a feature or two. Please install the latest update or switch to a modern browser. See you soon.

Search lists

#lists

The methods presented below can be used to find specific items or keywords in a list. If you want to filter a list with certain patterns or criteria, have a look at the how-to Filter lists.

Find (identical) items in a list (Item Index)

The component Item Indexcan be used to find the index of an item i in a list L.

The item to be searched for in a list, must be identical to the one that is provided as input. Every element in Grasshopper will get a unique ID, even if strings with equal content. Item Indexwill only compare those IDs. As seen in the figure below, the string with the same content will not return a positive match.

Find equal items in a list (Member Index)

The component Member Indexlooks for equal items in a list. The set (list) provided at input S is searched for members with the same values that are given at input M. The matching is done with a string comparison and we have to either provide one or attach data types that can be converted to strings in a sane manner, like text, numbers, etc. (in Grasshopper they are called Primitive Data Type). Points and vectors can also be cast to strings.

At output I we get the indices of the matches and at output N the number of occurrences for each member in the set.

Find similar items in a list (Find similar member)

The component Find similar memberis similar to Member Index, but instead of looking for equal members, it tries to match them by similarity. A set to search goes into input S and the data to search for into input D. Output H will return the most similar member and output i the corresponding index. One of the set’s members will always be the most alike, even if the returning item is quite different, but it’s still the best match.

Text-based search (Match Text)

The component Match Textis the most feature-rich search method, but only accepts strings, respectively data that can be converted to strings. The list of text to search is fed into input T and we can provide a search pattern at input P. We can also influence whether the search is case-sensitive at input C.

As an alternative to a pattern at P, we can also use a regular expression. A list of presumably supported expressions can be found here. For example, we can use ^.e to find text that has an e as second character.

This component will identify if a string matches a pattern and can not be used to extract a substring based on this pattern (like Regular Expression Capture Group does). This can be accomplished by implementing custom C# code, as shown in this how-to.

The component Key/Value Searchcan be used to search data in corresponding lists. This is useful, if data is given in a table format and we have a list for each column of the table. We can add key values at input K and linked values at input V. Then, the component will look for the keys at input S and return the corresponding matches at output R.

To search the other way around, especially if we don’t know the exact values of the linked data, a query with logical operatorsmight be more suitable. For example, we can use Dispatchto filter a list by given values.

Find geometrically identical objects

There is no ease way to find geometrically identical objects, which are equal or congruent. But, we can tweak the method describes for removing duplicate curves to search for matching criteria of geometric objects.

This page is open source. Edit it on GitHub or see how you can contribute.

Up next