Change room names according to existing elements

I would like to ask for help with this script.
I’m trying to change the names of the environments according to the type, I want to identify the type through the existing elements. In other words, I looked for the environments in my project, the room identifiers and the furniture (generic models) and I would like to change the names, for example, of an environment that has a model from Stove to KTC (kitchen), but I couldn’t get to that. As a result, I don’t have much experience with Dynamo. Could you help me, please? Any help is very welcome.

Can you setup an example of what you might have and how you would expect your graph to function? It’s a little difficult to understand exactly what you’re wanting right now. From my understanding, you want to collect elements to identify a room type in order to change names. What elements determine the type? Is the type dependent on all or just some of those elements existing? Is there any overlap in elements between types?

My guess is you would use a dictionary but I don’t know exactly what your lookup (list of elements?) would look like without knowing all the conditions.

1 Like

See, I have a plant with unnamed environments, all as “Ambiente”.
In each environment there are elements, for example, a bathroom with a shower, a kitchen with a refrigerator, etc. I would like to change the names of the environments automatically, and the reference I thought of using is; If there is a “shower” element in this environment, change the name of the environment to “Bathroom”. Do you understand?
Thank you for your attention.

So do you only need one particular element to exist in each environment to determine the type? If that’s the case then it’s pretty straight forward.

Create a dictionary of each element and its corresponding type. Get all the elements within an environment. Go through and check to see which elements exist in the environment to determine the name. If you have types that are based on two or more elements existing you would just nest those conditions.

Python would probably be the most straightforward option, but you could do it with nodes as well.

2 Likes

Sorry, I tried everything here, but I don’t know how to use the dictionaries, I even saw some of your posts here, but I didn’t get the results.
Could you explain me better?

The dictionary is really the last part. The first thing you need to do is define your conditions: which elements define which types. Then you need to get those elements into a list, matching your separate room list (which I think you mostly have in your first image). Then you’re probably using List.Contains to check the room element lists for your key elements. Once you have that then you can write a dictionary to map the names.

Your dictionary is then just the elements (lookup keys) that return a specific room type (values). Then you can provide the defining element of any room back to the dictionary to get the room type that it should be assigned.

1 Like

I think this image helps too (mainly because of the last node in the image).

1 Like

Exactly what I tried, but it gives an error and does not accept the results.

You don’t feed keys from a Dictionary in the bottom input in the last node.
You need to create and use a Dictionary.
Use @Nick_Boyts example for the Dictionary (bottom input) and feed your Elements in the top input in the last node.

1 Like

The error tells you the issue. Keys need to be strings in Dynamo dictionaries. Also, the key would likely be a stringified version of the element or elements that define a room type. That way, when you get the elements from a given room, if they match the predefined elements for a specific type, you can feed them into the dictionary to get that type.

You have to define a dictionary before you use it. That’s where you need to figure out what elements make up a specific room type. This will likely be a manual input.

1 Like

I’m not finding the same nodes, which package is this?

Nodes maybe called a little different depending on your Revit and Dynamo version. Nodes are all OOTB nodes, so no package needed.

Looking at your screenshot you should use the nodes from @Nick_Boyts example for
your Dictionary (I guess).

Using the term ‘Dictionary’ in the search bar should get you the nodes (I think).

1 Like

They’re the same out of the box nodes. Just renamed when they were updated a few versions ago.

1 Like

Understood. I converted my lists of environments and elements into texts and created the dictionary that tells me which environments contain which elements. But now I need to look for another list of environment identifiers (which I need to change the names), and filter which of these the elements are in and then change the name, but I keep making mistakes, shouldn’t this be step by step?

You have it backwards. The dictionary is for the environments and their identifiers. Then you can provide the actual elements in a room to return the matching environment (based on the identifiers) from the dictionary.

In fact, there’s no relationship between the elements and the rooms that you pulled here. They’re both just listed in order of ElementId. You need to make sure you get the elements from the rooms themselves for that part.

Also, you should be using String.FromObject (if not Element.Name or something else) to identify the rooms and elements for the dictionary. The node you’re using now converts a list to a single string.

Making mistakes is how you learn.

I am not behind a PC or else I could be bit more helpful.

After you have worked out the first step (the Dictonary part) then there will (probably) be a second step; Element.SetParameterValue.

But I would really suggest to recreate @Nick_Boyts example first to see how the Dictionary part works.

Babysteps :wink:.

1 Like

Here’s a simplified example of what we’re talking about:

1 Like

Luckily there is someone with access to Dynamo at this moment :sweat_smile:. I am at a phone :face_with_peeking_eye:.

1 Like

There might be a solution here for you.
The difference form your workflow is that you would want to get all the names of the room elements.
and i work MEP so i didn’t have any projects to test it on with rooms handy -_- so i just mocked up what i might looks lik, i hoipe you can understand.

It doesn’t feel like i understoof the assignment properly but it might help you :slight_smile:

Here you feed IN[0] with your list of Room Names
IN[1] is a list of all the elements in the rooms
IN[2] is a list of elements names / defining elements you are looking for.

If none is found, it will return the original room name input
If one is found, it will rename to that element.
If two are found, it will not find both. Simply 1 and stop.

Python - ℗ | RoomName.ByContents
def update_room_names(room_names, room_elements, revised_names):
    updated_names = room_names[:]

    for i, elements in enumerate(room_elements):
        for element in elements:
            if element in revised_names:
                updated_names[i] = revised_names[revised_names.index(element)]
                break

    return updated_names

_Var_RoomNames = IN[0]
_Var_RoomElements = IN[1]
_Var_RevisedNames = IN[2]
updated_room_names = update_room_names(_Var_RoomNames, _Var_RoomElements, _Var_RevisedNames)

OUT = updated_room_names
1 Like

Did you make any progress @cintiamiranda21?

1 Like