Transfer parameter values from Rooms to Asociated Doors

python

#1

Hi I am trying to modify/expand the functionality of Konrad Sobons python script - Door numbering from room number. - with no succes

My goal is to be able to also write:
Firerating - Acoustics - Automation -etc. from the rooms to the doors. (we are using dRofus and have all these information assigned here to the rooms)

Is it possible at all to extend the python script to extract these parameters and write them to the doors?
I have tried to write in as at test “room_department” in the python script with the same spelling but all I get is an empty list and a python node turning yellow.

This is my first attempt with python - I was just trying to get lucky with so logic assumptions on how it looks like it should work, but it seem that I do something fundamental wrong

import clr

Import RevitAPI

clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *

Import DocumentManager and TransactionManager

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

Start Transaction

doc = DocumentManager.Instance.CurrentDBDocument

fam_inst = IN[0]

elements = []
for i in IN[0]:
elements.append(UnwrapElement(i))

def TryGetToRoom(room, phase):
try:
toRoom = room.get_ToRoom(phase)
except:
toRoom = None
pass
return toRoom

def TryGetFromRoom(room, phase):
try:
fromRoom = room.get_FromRoom(phase)
except:
fromRoom = None
pass
return fromRoom

room_number, room_department, room_name, doors, room = [], [], [], [], []
for i in elements:
for phase in doc.Phases:
if i.CreatedPhaseId == phase.Id:
for phase2 in doc.Phases:
if TryGetToRoom(i, phase2) != None:
to_room = TryGetToRoom(i, phase2)
break
else:
to_room = None
for phase3 in doc.Phases:
if TryGetFromRoom(i, phase3) != None:
from_room = TryGetFromRoom(i, phase3)
break
else:
from_room = None

if from_room == None and to_room == None:
room_number.append(“No to or from room”)
room_name.append(“No to or from room”)
room_department.append(“No to or from room”)
doors.append(“No to or from room”)
elif to_room != None:
Numbers = to_room.GetParameters(“Number”)
Names = to_room.GetParameters(“Name”)
Departments = to_room.GetParameters(“Department”)
for n in range(len(Numbers)):
room_number.append(Numbers[n].AsString())
room_name.append(Names[n].AsString())
room_department.append(Departments[n].AsString())
doors.append(i)
room.append(to_room)

#Assign your output to the OUT variable
OUT = room_number, room_name, room_department, doors, room


#2

Looks like you may have some indentation errors, but I can’t see as we lost formatting. Can you repost with the formatting by selecting your code and hitting the preformatted text button (it’s the </> butting next to the quote) on the toolbar?

Also expand the error and post it so we can see that as well - really helps narrow things down.

Lastly, could you use regular nodes here? May be easier to wrap your head around as this isn’t easy for a ‘my first Python’ type of task.


#3

Thanks Jacob for getting me on the right track

As you suggested I made the extension with regular nodes
This is a test where I wrote areas from rooms to finish Doors just to check it worked