room numbering with dynamo

Here’s a quick video preview of this workflow: YouTube

Following up on Window/Door Numbering tools that I was working on previously, I wanted to add another aspect to it. Below is a workflow that will allow you to automatically number rooms. Combining those two tools we can significantly reduce time that it takes to produce this basic yet extremely important piece of information. It will also, eliminate the human error factor out of the Room/Door/Window numbering and ensure that our schedules are fully coordinated. Here’s a workflow in detail:

1. First we start by collecting all of the rooms on a given floor. I like to do this per floor because I want to keep the room numbers organized per floor. For example I want Ground Floor rooms to be in 100 series, First Floor in 200 series and so on. I use a Get Rooms by Level node that I made earlier and posted to Package Manager. However, that node collects all rooms, regardless of whether they are actually placed or not. I use a little bit of Python to filter out all Redundant Rooms. Then all I need is room location to get me started on sorting their order.

Collect all rooms on level

Python code to filter out unplaced rooms:

#The input to this node will be stored in the IN variable.
dataEnteringNode = IN
rooms = IN
valid_room, room_name = [], []
for i in rooms:
    if i.Area != 0:
        valid_room.append(i)
#Assign your output to the OUT variable
OUT = valid_room

2. Next is the meat of this workflow. I use Python to sort rooms into the order that I want them in (left to right and top to bottom). I need to extract Y Axis value, X Axis value as well as give it  an input number for how many imaginary rows I am splitting my plan into. Here’s a Python code:

 # Default imports
import clr
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.DB import *
import Autodesk
import sys
import clr
path = r’C:\Autodesk\Dynamo\Core’
exec_path = r’C:\Autodesk\Dynamo\Core\dll’
pyt_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’
sys.path.append(path)
sys.path.append(exec_path)
sys.path.append(pyt_path)
clr.AddReference(‘LibGNet’)
from Autodesk.LibG import *

#The input to this node will be stored in the IN0…INX variable(s).
dataEnteringNode = IN0

from itertools import groupby
import string

yAxis = IN0
xAxis = IN1
room = IN2
numRange = IN3
lst = []

#convert yaxis values from revit length to strings and strip “m”, “mm” or “ft” designation
for i in yAxis:
    lst.append(float(i.ToString().strip(string.ascii_letters)))
#define range min and max values, step
lstMin = min(lst)
lstMax = max(lst) + 1e-12
step = (lstMax – lstMin) / numRange
#convert yaxis values to corresponding ranges
rangeNum = [int((x-lstMin) / step) for x in lst]
#sort input lists into corresponding groups then sort values within them
grps = sorted(zip(rangeNum, xAxis, room), key=lambda x: (x[0], x[1]))
rangeNum, xAxis, room = [], [] ,[]
for i, grp in groupby(grps, lambda x: x[0]):
    sub_rangeNum, sub_xAxis, sub_room = [], [] ,[]
    for j in grp:
        sub_rangeNum.append(j[0])
        sub_xAxis.append(j[1])
        sub_room.append(j[2])
    sub_rangeNum, sub_xAxis, sub_room.reverse()
    rangeNum.extend(sub_rangeNum)
    xAxis.extend(sub_xAxis)
    room.extend(sub_room)
rangeNum, xAxis, room.reverse()

#define outputs
OUT = rangeNum, xAxis, room

I am giving you here the entire code because I am using an import function and a custom module called itertools. Make sure that you have a proper path to it appended otherwise you will get an error.

3. Once we have out rooms all sorted in a proper order all we need to do is to assign a proper room number to them. Like I mentioned before I wanted to assign numbers in series of 100s based on level that I am on. I also wanted ability to skip a certain number and its multiples of 10. Here’s a process to achieve that:

create number sequence

Here’s code for Numbering Sequence with Skip node. I also made that node available on Package Manager.

#The input to this node will be stored in the IN0…INX variable(s).
dataEnteringNode = IN0
lstLength = IN0
skipNum = IN2
count = int(IN1)
lst = []

while len(lst) < lstLength:
    count +=1
    if count % 10 == skipNum:
        continue
    countFormat = str(count).zfill(3)
    lst.append(countFormat)

#define outputs
OUT = lst

4. Once we have our number sequence all we need to do is pass it on to rooms. I used a custom node called Set List Instance Parameters to achieve that. You will need a Transaction node with it since we are modifying a Revit Database by changing room numbers.

I hope this helps some of you save some time. Make sure to check out the Window/Door Numbering post that I have made earlier. Those two workflow combined can be a huge time saver.

Good luck!

Ps. This post has been recently updated to Dynamo 0.8.0 and can be found at Door Numbering for Dynamo 0.8.0

 

Support archi-lab on Patreon!

12 Comments

  1. Dmitry Dronov says:

    Hi.
    Konrad, tell me please, where i can find “Get Element Location.dyf” file, or how i can create it. thx

  2. Dmitry Dronov says:

    thx.
    one more question.
    I use Dynamo 0.7.1 and there i can not find nods XYZ X and XYZ Y… where i can find it?

  3. Thanks a lot.
    I want to say one more thing.
    When i copy-pasting your script, i need to change symbols ‘ and ’ on ‘
    And symbol – on –
    It is very important for coding.

    And one more… in dynamo 0.6.3 was appeared “SetElementParameter” nod instead script
    thanks a lot.
    it worked

  4. kulkul says:

    Hi,
    Konrad thanks for sharing dynamo nodes. I am using dynamo 0.8. Can you send me the download link for room numbering dynamo.

  5. kkillian says:

    Where can I find the select_level_from_list.dyf? I don’t see it in the package, or maybe Im missing how it is created from the door numbering from dynamo example?

Leave a Comment