Filtering Dictionaries in Dynamo based on the values in the dictioanry

Hi Everyone!

Can some please help me how can i filter the dictionaries based on the key values within the dictionary,

I am creating walls from lines.
Each Dictionary has two keys and values
Key 01 Element ID: (consists line id)
Key 02 Walls ID: (Wall created from the respective line)

I created the dictioanry for each line and its assosiated walls.

Now i want to filter out the dictionaries whose walls are deleted in the model so that i can recreate them.

I dont know how can i filter the dictionaries based on the Wall ID key if that wall is still present in the model or not.
Here is the dynamo graph

Thanks

What’s your reason for using dictionaries with generic keys? Using the same key (as essentially a name) for each dictionary object within multiple dictionaries kinda defeats the purpose of dictionaries in the first place.

If you want to maintain a relationship of lines and walls, then you would make that your dictionary: key = WallId, value = LineId. Then your lookup is just providing the WallId to the dictionary to get the corresponding line.

However, in your case, I don’t think that’s the most helpful solution. The purpose of a dictionary is to retrieve specific keyed values from a provided key. You’re essentially looking for the inverse of that: provided a list of keys, return all values that weren’t identified. You could do that by removing key, value pairs from your dictionary but then you’re not really using the dictionary at all.

I think we need more information to give you a better suggestion, but I think you’d be better off just filtering values from your list.

Thanks for your response. i will try your approach also.

But the thing is that in future i will be creating 3 parallel walls from one line. for that reason the line ID will be my main dictionary. The wall id will consists 3 walls.

Can you please guide if its possible to filter dictionary based on the nested dictionary key values as in my example.

Or in my example how can i filter this dictionary based on if the wall id is present or not. Thanks

So you’re a bit hung up on the terms here. Dictionaries cannot be filtered. Lists can.

But you don’t have a dictionary, you have a list of dictionaries.

So you can ask each dictionary in the list for the value of key 1, and then test the result of that using a logical test of your choosing.

Something like this:
List.FilterByBoolMask( dictList, dictList[“ElementId”] == target )[“in”];

So are you checking for all 3 walls to exist or just one? What happens when one wall has been deleted and the others haven’t?

Filtering for the missing values still feels like a backwards way to use a dictionary to me. If I’m understanding your workflow correctly, I’d still use a list to filter by first before using a dictionary for the walls.

  1. Compare existing walls with list of expected walls.
  2. Use list of missing/deleted walls to filter corresponding line list.
  3. Provide line as key to dictionary of walls by line.

If each line is used to create 3 walls, then you need to know which ones to create and which to ignore if one or more is missing. Having a dictionary with all expected walls allows you to filter that list by what’s missing. Or even just delete and redraw all 3.

Dictionary.RemoveKeys would like you “filter” the dictionary after you compared wall Ids, but something like this would let you check for missing walls and then return the line that determines that wall as well as the expected set of walls for that line.

1 Like

Thanks for your suggestion. I tried what you explained and created the script.

What i want is that i have a lot of repetitive floorplans in the project and across different projects. I created family which consists of line based nested families and each line based family represent a wall type. i want to create walls from these lines, update the walls if lines are updated, create new walls if new lines are added and delete the walls if lines are deleted.

I did the script it works good but it does not cover all the scenarios. I export the data to json on each run and on the next run i compare it with existing revit walls and lines.

The script works good for the first time and when i move the lines it updates the walls. But if i add new walls, delete some walls and move some lines like all together. the script gets confused and it doesn’t give the right result.

Can you please guide me what i am doing wrong here?

For the lines i am using line based family with the wall type name as a description parameter and i use the location of line based family for my walls.

I can upload the dynamo script and family but its not allowing me to upload.

Why not just let element binding do it’s trick? You’ll have to save a version of the graph for each project but that isn’t hard to manage. Updating locations and removing/adding instances like this is what it was built for.

I guess that’s only possible if dynamo is open. we are creating a workflow for other colleagues to make it simple for them so that they can just click button either dynamo player or maybe later change it to pyrevit button. its just a start so that i know how can achieve that functionality. later on we will be doing it for lot of other elements.

we are creating prefabricated walls. which consists ot needs sometimes to make 3 4 layers of walls modelled separately.
once i achieve it for the simple example i can update it for other cases. I dont know what i am doing wrong here in my script. the problem is with exporting to json and importing back. somewhere in between working with dictionaries it mixes the walls ids and lines ids.

I created the same workflow where i was pushing the wall id to a custom parameter of a line based family and it was working perfect even for 3 layers walls. but still i need to export it to json because if a line is deleted i want the walls also to be deleted. thats why i switched to the approach of json. i am doing something wrong with filtering dictionaries and than setting the values back again to dictioanries.

Is there any other way i can provide you the family and dynamo script if you can have a lookin it. i will highly appreciate it. Thanks for you time and response.

Why not use a real wall and make parts?

Thats not possible for us either we tried it. Thats lot of manual work and also for us each wall length is different. its easy for us to make it separate. its working good for us. we just need to automate it.

As i said its working fine when i create a 3 layer wall from line base family. i push the walls id to its each line based family, The problem was when the line is deleted i cant get the walls ids to delete that walls. also if a user copy the lines it will also the copy the walls ids which were stored in a parameter. and after running a script its creates issues. Thats why we though we can give it a try with json.

I can share my script with you. if you have a chance to look in to it. what i am doing wrong. i also uploaded the family. Thanks millions

I know quite a few who are using parts for this, including much more complex examples. All of what happens with those can also be automated in the end, though manual tweaks require learning some new tools in Revit.

This sort of functionality is available in the API via an event triggered from an event listener. Some have hacked at Dynamo to make event listeners possible (you can find examples on the forum), but it is certainly easier in C# as a Revit add-in. If that is what you are after I suggest now that you have a working method you skip past Python and into C# to build one Dynamo node as a zero touch node, and then move into a full Revit add-in.

I am not at my CPU for the weekend, and will be traveling Monday a d Tuesday next week, then won’t be at my CPU on the holiday Wednesday… If my Thursday and Friday don’t wind up being overbooked due things piling up over the previous 3 days I’ll try and take a look then. :slight_smile:

Ironically this week’s video deals with iupdater/listening:

He builds in pyrevit but maybe useful still.

1 Like