my script works well, unit i call the room of my beamer ?
how can i get my instances based on that ?
my code so far?
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# 📐🌈 Linked electromodel
linked_docs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements()
lnkInstance = [i for i in linked_docs if i.Name.Contains("FM_E")]
doclnk = lnkInstance[0].GetLinkDocument()
# 0️⃣ get rooms
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
# 🏓 get beamers
devices = FilteredElementCollector(doclnk).OfCategory(BuiltInCategory.OST_AudioVisualDevices).WhereElementIsNotElementType().ToElements()
beamer = [ i for i in devices if i.Symbol.FamilyName.Contains("Beamer")]
roomBeamer = [i.Room for i in beamer]
OUT = rooms, devices, roomBeamer
You could use CPython3 or use the get_Room() method
phases = {ph.Name: ph for ph in doc.Phases}
phase = phases["New Construction"] # Use the required phase name
roomBeamer = [i.get_Room(phase) for i in beamer]
Items without a room or not associated with the phase will return null
import clr
import sys
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# 📐🌈 Linked electromodel
linked_docs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().ToElements()
lnkInstance = [i for i in linked_docs if i.Name.Contains("FM_E")]
doclnk = lnkInstance[0].GetLinkDocument()
# 0️⃣ get rooms
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
# 🏓 get beamers
devices = FilteredElementCollector(doclnk).OfCategory(BuiltInCategory.OST_AudioVisualDevices).WhereElementIsNotElementType().ToElements()
beamers = [ i for i in devices if i.Symbol.FamilyName.Contains("Beamer")]
locationPoints = [i.Location.Point for i in beamers]
points = [i.ToPoint() for i in locationPoints]
output = []
for i in points:
if doc.GetRoomAtPoint(i.ToXyz()) == None:
output.append("No Room")
else:
output.append(doc.GetRoomAtPoint(i.ToXyz()))
OUT = output
I’ve had cases where the default Room property doesn’t work and I’ve always been able to work around it with the get_Room[Phase] method. You just need to make sure you’re providing the correct phase otherwise you’ll get a null. Although GetRoomAtPoint is valid as long as you ensure you’re using the right phase again.
output = []
for i in points:
if doc.GetRoomAtPoint(i.ToXyz()) == None:
output.append("No Room")
else:
output.append(doc.GetRoomAtPoint(i.ToXyz()))
OUT = output
You actually are. The default method (with no phase specified) uses the last phase in the project - same as the Room property. Both methods have alternatives to specify the phase you want to query for rooms. It’s usually pretty safe to assume the final phase is accurate for room data, since most projects don’t require rooms on multiple phases anyway.
an example, when rooms are not necessarily created in the last phase
import sys
import clr
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
import Autodesk.Revit.DB as DB
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
doors = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()
room_location_doors = []
for elem in doors:
room = next((elem.get_Room(ph) for ph in doc.Phases if elem.GetPhaseStatus(ph.Id) == DB.ElementOnPhaseStatus.New), None)
room_location_doors.append([elem, room])
OUT = room_location_doors