Hi, I have this python code i was meant to insert into a python script node. I cleaned all the white space and replaced with tabs but i am getting no values when i insert all categories of doors. Can anyone possibly tell me why? Im using dynamo 1.2 and revit 2017.2. The Python Script is meant to pull and list information from the doors, mainly to and from room info.
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_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")
doors.append("No to or from room")
elif to_room != None:
Numbers = to_room.GetParameters("Number")
Names = to_room.GetParameters("Name")
for n in range(len(Numbers)):
room_number.append(Numbers[n].AsString())
room_name.append(Names[n].AsString())
doors.append(i)
room.append(to_room)
#Assign your output to the OUT variable
OUT = room_number, room_name, doors, room
FYI, Python coding is pretty strict in relation to spaces or tabs.
You can use programs like Notepad++ or Atom to Strip & Replace whitespace etc and format it correctly.
The code was off youtube comments. Made sure i replaced spaces with tabs carefully. Double checked the code was the same space off the video i was watching too
It’s all right, I am not usually concerned too much if you were to take it and make changes or improvements and then post back, but this seems to be largely unchanged from the original. Anyways, this is the source: http://archi-lab.net/door-numbering-v2-0-for-dynamo-0-8-0/
This is the latest, last time I worked on this code:
# Copyright(c) 2017, Konrad Sobon
# @arch_laboratory, http://archi-lab.net
# Import RevitAPI
import clr
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
doc = DocumentManager.Instance.CurrentDBDocument
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
filter = IN[1]
filter2 = IN[2]
fam_inst = IN[0]
phase = UnwrapElement(IN[3])
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
def GetFromToNames(door, phase, f = filter, f2 = filter2):
fromName = ""
fromRoom = TryGetFromRoom(door, phase)
if fromRoom != None:
fromName = fromRoom.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
toName = ""
toRoom = TryGetToRoom(door, phase)
if toRoom != None:
toName = toRoom.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
# Filter2 - where doors are outswinging from electrical closets etc.
if fromName != "" and any(fromName == x for x in filter2):
return [door, fromRoom]
if toName == "" or any(toName == x for x in filter):
if fromName == "" or any(fromName == x for x in filter):
return [door, toRoom]
else:
return [door, fromRoom]
elif any(fromName == x for x in filter):
return [door, toRoom]
elif any(toName == x for x in filter):
#return [door, fromRoom]
return ["", ""]
else:
return [door, toRoom]
output = []
for door in IN[0]:
output.append(GetFromToNames(UnwrapElement(door), phase))
#Assign your output to the OUT variable
OUT = output
I think I removed bunch of stuff. I am not sure why, but maybe it was not really needed down the line.
I’m sorry I cant remember what happened with using this. I think I just reverted back to my door renumber with model line spline Door-Renumber-With-Prefix.dyn (16.4 KB)