Sort rooms by number (sort list by value)

Hello everyone,
I need some help please.

I copied and modified this routine in order to extract room data onto excel and back to the rooms themselves in real time (when running automatic every time I save the excel my rooms changed and when I change soth in the file the excel change).

The problem is that the rooms come out sorted “by Level” and not by “Room number”
please follow link to find printscreens and dyn file:
https://drive.google.com/drive/folders/15HoJVHfGeET5GkQcUw8rH4RnfskbW1z0?usp=sharing

I need to be able to sort the rooms (By number) on the way out to excel and sort them back to their original state on their way back to Revit. If I don’t do this all my room in Revit flip values!

I receive suggestions. My original idea might be very silly as I am new here.

I also get this annoying warning every time I save the excel. But when I save the excel a few times the data finally goes through. weird…

Thanks a lot!

Best,
Axel

Hi @axelibarroule,

try sorting the rooms first using the List.SortyByKey node (List=RoomElements, Keys=RoomNumber) and then use the sorted List to get each parameter and the sorted keys as your RoomNumbers.

Works for me. Best regards

1 Like

hello @dudinger,
thanks a lot!!! you can’t imagine how long I’ve tried this.
It´´ a great improvement! It did excatly what I asked for. Now I realize I have another problem though.

Can we make it believe that they are numbers? or should I set that in Revit. Because at the moment it’s organizing it as if they where characters.
10
101
102

intead of
10
11
12
and then the hundreds.

My previous question was also if there`s any way to revert it when I send it back to revit. Because if not, it shuffles all my rooms again.

thanky you so so much.

Hi @axelibarroule,

one way to sort the the numbers correctly would be the string.padleft node which adds a certain character until it reaches the chosen width.

What do mean with revert when sending back to Revit?
Best regards

Edit: If the room numbers/names get shuffled try using the sorted list for your setParameter node at the end instead of the “All Elements of Category”.

hello @dudinger,
nice! wow you are really helping me out here. thanks so much.
padlef worked like a charm.

What do mean with revert when sending back to Revit?

I mean that the values that I modify in the excel go back to my Rooms parameters in revit. And because I am changing the order of the Keys and values, revit changes them according to the new excel order. This creates a terrible mess and sometime a never ending loop that crushes the software.

Now everything is working perfectly up to the moment where I want to bring the values back to revit.

thank you again and again.

You don’t need any sorting at all with this method.

Hi @axelibarroule,

first of all you have to connect the sorted List to the setParameter nodes.

What does the speech bubble above your ImportExcel node say?
For me it works perfectly this way.

amazing! errors gone. and data flowing like a river!
Thanks a lot @dudinger
I believe the occupancy error came because some rooms where set to less than 1.

Here’s a printscreen of the final routine (If that`s what you people call it)


Thanks again.

1 Like

Transferring data based on order alone can be a bit shaky - obviously it is working for you at the moment, and that is what counts :smiley: but a method using an ID like Marcel suggested or using dictionaries to “call” the right room for your row of data is more resilient.

As Marcel posted already a way to do it with UniqueID and ElementSelector method, here a quick sketch of how to do it with dictionaries, which make it easier to expand the list of parameters to be synced between revit and excel, as you don´t need to worry about feeding the “right” index to the get item at index node

thanks @halfbaked @marcel_rijsmus
it is actuallly very important that I can trust the thing not glitching.
I will give it a go and come back to you once I’ve done so.
thanks again

Hello @Marcel_Rijsmus,
That was a very clear tutorial. Thanks for that.
Unfortunately I have a problem that you might be able to help me with:

Thank you again.

There is no UniqueID in you excel sheet.
You need to get the UniqueId from the rooms, there is a node for that.

1 Like

HI @HalfBaked,
I also tried your proposal but I also have problems. Sorry about that:

Do I have to do all of this for each parameter?
Do you think @Marcel_Rijsmus is somewhat cleaner?

Thanks a lot!

@Marcel_Rijsmus,
sorry for the silly question. It was perfectly explained in your post. It is a verz clever solution!

Everything is working quite perfectly. I do have one last question if possible.
I can’t get the “rounddown node” from clock work. I believe a version conflict.

Is there any way around this without clockwork?

Thanks a lot Marcel.

Hi,
I see three problems:

  • you are not creating the room dictionary, so your value at key node to pick the right room has no source of data
  • your excel sheet needs headers, and those headers needs to be equal to the name of the revit parameters, in order to build your set of dictionaries to pick values from.
  • you need a data stream await node, to be sure that you are reading your excel file after you have written it

You can feed your GetParameterValue a list of parameter names and output them all to excel - you don´t need to add a node for each parameters, as long as you keep your list structure clean. You should /could a separate node to extract the value you are going to use as an ID though, for clearness´ sake - but it´s important that you send those values to excel as well.

Marcel´s solution is described way better :smiley: but otherwise the methods are pretty similar - you don´t have to use the room number, you can use the uniqueID as key as well - but I think that using a dictionary and calling the parameters by name is a more solid solution than calling them by their index number, but for a small number of parameters it shouldn´t really matter.

Hey @HalfBaked,
Thank you very much for taking the time. I am very grateful. Everything you say makes alot of sense. I followed and tried a few of those but I’m not able to connect everything together. Also my experience in dynamo as you can tell is very short.

you are not creating the room dictionary, so your value at key node to pick the right room has no source of data.

is this what you mean?

your excel sheet needs headers, and those headers needs to be equal to the name of the revit parameters, in order to build your set of dictionaries to pick values from.

You mean I need to create an Excel before I even start? Because so far the excel was created automatically.

you need a data stream await node, to be sure that you are reading your excel file after you have written it

Is this something I can download somewhere ? If it’s not I might cry.

You can feed your GetParameterValue a list of parameter names and output them all to excel - you don´t need to add a node for each parameters, as long as you keep your list structure clean. You should /could a separate node to extract the value you are going to use as an ID though, for clearness´ sake - but it´s important that you send those values to excel as well.

When I feed a list of names as you suggest I get this weird outcome:

@HalfBaked,
I’m sorry I`m taking so much of your time… I’ve been requested to feed a huge database into Revit in my office as my first attempt in dynamo :S THey overdid it this tihe haha
I attached my dyn file and revit file so you can check my errors.

room-excel_sorted .rvt (3.1 MB)
room-excel_nonsorted2.dyn (49.4 KB)

Hope you can help me out just a little more.
:smile:
Axel

is this what you mean?

more or less - you have to feed actual values in order to create a dictionary (the values of the room numbers, or of their uniqueID, or whatever else is unique to each room).

I suggest going over the relevant chapetr in the Dynamo primer: https://primer.dynamobim.org/09_Dictionaries/9-1_What-is-a-dictionary.html

You mean I need to create an Excel before I even start? Because so far the excel was created automatically.

No, I mean that you need to feed your ExcelWrite node the values to put in the headers as well. Something that looks like this

and gives you an output like this

grafik

in order for you to be able to read the first row as your keys and the rest of the data as your values for your dictionaries down the road to fill the data back into your rooms.

Is this something I can download somewhere ? If it’s not I might cry.

Orchid has DataStream.Await, and Clockwork has Passthrough . No need for tears :smiley:

When I feed a list of names as you suggest I get this weird outcome:

Try setting the lacing to cross product

I’m sorry I`m taking so much of your time… I’ve been requested to feed a huge database into Revit in my office as my first attempt in dynamo :S THey overdid it this tihe haha

we´re all been there :slight_smile: good luck!

1 Like