Furniture name by room name

Good evening, I’m writing here because I need your help. I’m working on my thesis and a part of its, it’s the facility management and I would do it for the furniture. How can I tag all furniture with room number (for example in the room 101 I have 5 desks and 5 chairs, so the number should be: 101d1, 101d2, 101d3,… for desks and 101c1, 101c2, 101c3,… for chairs, ecc)?
Thank you so much!

Take a look into this thread:

Hello @cristina.vagnozzi,
you could also try this road:



hope it helps :slight_smile:

2 Likes

Hi Ernesto, thanks for your reply. I did your solution and it works but there isn’t the number of the room. There’s just the word “Room”

How can I do to get the number? I’ve replicate your scheme.

Hi, @cristina.vagnozzi! Try this solution for your task:


Code for copy pasting:

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import BuiltInParameter
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from operator import itemgetter
from itertools import groupby

rooms = UnwrapElement(IN[0])
furniture = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)
furniture_list = []
for i in furniture:
	loc = i.Location.Point    #get location of furniture instance
	room = doc.GetRoomAtPoint(loc)	#get room at that location
	number = room.Number #get number of room
	furn_mark = i.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)  #get Mark parameter of furniture
	name = i.Name  #get Type name of furniture
	furn_mark.Set(number+name)  #set new value to Mark parameter (number+name type)
 	furniture_list.append([i, room.Number+name]) #creating new list for further manipulation
 
furniture_list.sort(key=itemgetter(1)) #sorting new list by same room names
newlist = [[x for x,y in g]
for k,g in groupby(furniture_list,key=itemgetter(1))]

for k in newlist: #adding to Mark parameter count index of furniture in each room
	count = 1
	for item in k:
		furn_mark = item.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
		furn_mark.Set(furn_mark.AsString()+str(count)) #adding index to Mark parameter
		count+=1
TransactionManager.Instance.TransactionTaskDone()

OUT = furniture_list, newlist

Here is the result:
image
area room.dyn (10.1 KB)

Thank you Dmytro for the reply. Unfortunately it didn’t work beacuse I’ve a notice on the python script. How is it possible?

Your welcome. You can try to download original dyn file, or just upload a screenshot of the error

I downloaded dyn file but can’t be opened. This’s the screenshot of the error


The error is in italian. In english is "Notice: IronPythonEvaluator. EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 20, in
AttributeError: ‘NoneType’ object has no attribute ‘Number’ "

Oh, my mistake… its because in your model there are furnitures outside rooms. Replace code with this one. This script works only with furnitures that are located in rooms

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import BuiltInParameter
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from operator import itemgetter
from itertools import groupby

rooms = UnwrapElement(IN[0])
furniture = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)
furniture_list = []
for i in furniture:
	try:
		loc = i.Location.Point    #get location of furniture instance
		room = doc.GetRoomAtPoint(loc)	#get room at that location
		number = room.Number #get number of room
		furn_mark = i.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)  #get Mark parameter of furniture
		name = i.Name  #get Type name of furniture
		furn_mark.Set(number+name)  #set new value to Mark parameter (number+name type)
		furniture_list.append([i, room.Number+name]) #creating new list for further manipulation
	except:
		0
furniture_list.sort(key=itemgetter(1)) #sorting new list by same room names
newlist = [[x for x,y in g]
for k,g in groupby(furniture_list,key=itemgetter(1))]

for k in newlist: #adding to Mark parameter count index of furniture in each room
	count = 1
	for item in k:
		furn_mark = item.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
		furn_mark.Set(furn_mark.AsString()+str(count)) #adding index to Mark parameter
		count+=1
TransactionManager.Instance.TransactionTaskDone()

OUT = furniture_list, newlist

Just for clarity. In my case index ‘C’ and ‘B’ is a family type name

I haven’t there aren’t furniture outside rooms. All furniture are inside! Unfortunately new script it doesn’t work because revit isn’t responding when I run the configuration with this new script.

I would go back to this version of the graph: Furniture name by room name

Replace the Elements.Name code block with an Element.GetParameterValueByName node where the parameter name is the room number or room name (not sure what you are appending).

At least you can try to do the same thing on blank project, with not many elements. If it works then maybe there are too many elements in your main model and its a question of time for script to solve the task.
If not, then im not sure what is wrong and my apologies - i hope someone will give you an assist

1 Like

Thank you Jacob. I did as you suggested me. There are no errors but I can’t see the number of room. I would have a configuration as “221D_01”, where 221 is the number of the room. The scheme I’ve set is this:

.
The result I get is this: .
As you can see in the tag misses the number of the room. Where would be the mistake?
Also I would that the number after the “_” restart for each room (for exampe 221D_01, 221D_02,…; 222D_01, 222D_02,… ).
Is it possible?
Thank you so much for your help!

Enable all node previews, and post an exported image of the Dynamo graph (use the camera export in the top right after zooming in so the previews are legible). It may be that the parameter name is spelled incorrectly.

Really thank you for your kindness! This is the export:

.
Is there any mistake?

I think you need to replace the code block Number with the string “Number”

Try copy/paste “Number”; inside your code block ( including quotation marks “” and semicolon ; )

image

Unfortunately nothing is changing. There could be some other mistake? I’ve tried with both solution: replacing the code block Number with the string "number, and copy/paste “Number”; in code block, but the result is the same before.

The quotes identify data as a string in a code block. If you use a string node there is no need for them, as Dynamo already knows what the data type is.

So remove the quotes and the ; from the string node and it should update. Also, turn on all the node previews if this doesn’t update.

2 Likes

Finally I get it!! Really thank you so much for your help!!