Hi,
It seems like a simple job but I am stuck with this task.
I have to find string items of ListA in ListB. However, with a condition that I dont have to write exact same string, meaning, that the funtion retrieves values closest to the string that I demanded.
Ideally, String.Contains should work, i tried to adjust NodeLevels, no luck so far.
Reason being LevelNames are long strings and chances of mistake is higher for other users.
ps. I like to add some context: I am trying the replicate the method from this tutorial, so I can create sheets directly from Levels. In reality, projects dont have just 2 levels for each floor: Each floor has around 4-5 levels, hence I need a selection toggle, or just type the levels I need. The project I am working has around 50 levels and its hard to even search through a drop down menu. Typing seems like the best option.
Auto-Documentation With Dynamo! Part 1 - Create Views, Sheets, and Drop Views on Sheets - YouTube
hi
use String Contains with cross product lacing, then use anytrue node @L2
Thanks, lacing totally slipped my mind.
However, the method worked partially, not exactly what I intended. I want to search listA strings that contains all the alphabets of listB string.
There are lot of items in listA that contains letters âegâ, but only one item that contains âeg ffbâ.
Is there a way to search string like that ? or
There is only one item that contains letters â1 og ffbâ.
Hi Guys
Canât find it because itâs looking for âog ffbâ.
When I did âogâ it worked properly.
1 Like
yes, I am having the same problem
I was thinking if anyone expert in CodeBlocks can tell us, if there is a way to split string and search,
something like ⌠instead of searching âeg ffbâ, we could search âeg+ffbâ. so it searches âegâ, and then eg with âffbâ ?
so I asked a friend, he guided me to a python logic.
I am still struggling to get the desired result.
So, using same script, i can filter all elements that has âEGâ and âOGâ in name, but I want to further filter down to item that has âEG FFBâ. How would that work ?
You can only check a single continuous substring at a time without getting into RegEx. âThis Thatâ is not the same as âThisâ and âThatâ. What youâre really asking is to search for two substrings at the same time, so thatâs what you have to do.
Python
listA = IN[0]
listB = IN[1]
out = []
for a in listA:
for b in listB:
allPass = 0
for sub in b:
if sub in a:
allPass += 1
if allPass == len(b):
out.append(a)
OUT = out
Thank you Nick for detailed solution. Python and Dynamo both.
I copied your script and it didnt give me results I intended. I would like to add here that I am a beginner at python, so I wasnt able to edit your script. I like to understand the logic behind âallPassâ though, I checked some python tutorials about âallPassâ they were talking about wave funtions and complex equations.
Secondly, a non-AEC friend:) asked me to use get_close_match funtion. It makes more sense as it is simpler to understand. I am posting both scripts here for experts to see if itâs the right way to go. So far I am getting the results I wanted. Just have one more look before I mark this post as resolved.
PS. In cutoff value, I was wonderig if it is possible in DynamoPython to use âgreater than or equal toâ ?
I tried using >= but it didnt work. Just curious !
Using close_matches
is a great solution but might be somewhat inconsistent depending on how varied your strings are. Just keep that in mind.
As for the example I gave, youâre still using single substrings. As Iâve already mentioned, that will not work with searching. If you look at my graph youâll see I split each âsearchâ value into a list of substrings so that the code can check for each one individually.
The allPass
Iâm using is just a variable to make sure that all substrings within a search value are found within a string in order to be accepted.