How to get the room from my linked electrical elements?

Hello,

so far it works with my ruff script, BUT … i get no rooms

import clr

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

Elements = UnwrapElement(IN[0])

OUT = []

for i in Elements:
	OUT.append(i.Room)

i want to count my poweroutlets i have different ones… and also other stuff, i have to address them to my rooms!

KR

Andreas

We can’t see what you’re supplying the python node but I think LinkElement is a custom class, not a Revit one, so those objects won’t work with the API.

1 Like

@Nick_Boyts ,

how can i get the outlets? room by room… ?

Geoemtry intersect?

KR

Andreas

You can still use the method you’re using, you just have to supply Revit elements and not a custom class from a custom package.

1 Like

@Nick_Boyts ,

something like this?

Yes. Now I think you have to use the Room (Phase) property since these are linked elements. Otherwise it’s probably looking the last phase in the active document.

1 Like

@Nick_Boyts

i can`t find nothing similar… have i sort by phase my rooms? they are all new

Get the phases from the link document and then check for a room at each phase (or just the last one if you know that’s where all the rooms exist.)

2 Likes

@Nick_Boyts ,

thanks i will check out tomorrow

@Nick_Boyts ,

thats what i have so far… names of the variables are not correct

i want to get rooms of my outles! the outlets are linked. Rooms are in current doc!

import clr

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
docLink = FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements()[0]

outlets = UnwrapElement(IN[0])

FromRoom = []

for i in outlets:
	for phase in docLink.Phases:
		if i.CreatedPhaseId == phase.Id:
			try:
				from_room = i.FromRoom[phase]
				FromRoom.append(from_room)
			except:
				FromRoom.append(None)
			continue


OUT = FromRoom

KR

Andreas

  1. get the location of your outlet:
    pt = outlet.Location.Point
  2. get phases
    phases = [p for p in doc.Phases]
    phases.reverse() # check last phase first
  3. check its room:
    for p in phases:
    room = doc.GetRoomAtPoint(pt, p)
    if room:
    break
2 Likes

This is the critical information we were missing.

An element has to have access to a room in order for Revit to know it’s located there. In the active model, that can either be in the same document or a linked one (as long as the rooms are loaded). In a linked document, the elements won’t check the active model for rooms.

In this case, you have to go by geometry/location - something like @newshunhk has suggested.

1 Like

@newshunhk @Nick_Boyts ,

ok until phase reverse it runs well… but the last part does not work… i am not shure about collecting the rooms…

import clr

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

outlets = UnwrapElement(IN[0])

#get the location of your outlet:
pt = []
output = []

for i in outlets:
	pt.append(i.Location.Point)
#get phases
phases = [p for p in doc.Phases]
phases.reverse() # check last phase first
#check its room:
for p in phases:
	room = doc.GetRoomAtPoint(pt, p)
		if room:
			output.append(p)
		break


OUT = output

grafik
KR
Andreas

Tells you right there you have an unexpected indent. Your if/break loop at the end has an extra indent under room.

@Nick_Boyts ,

it still remains

outlets = UnwrapElement(IN[0])

#get the location of your outlet:
pt = []
output = []

for i in outlets:
	pt.append(i.Location.Point)
#get phases
phases = [p for p in doc.Phases]
phases.reverse() # check last phase first
#check its room:
for p in phases:
room = doc.GetRoomAtPoint(pt, p)
	if room:
		output.append(p)
	break


OUT = output

The room and if/break lines should be aligned.

for p in phases:
    room = doc.GetRoomAtPoint(pt, p)
	if room:
		output.append(p)
	break
1 Like

@Nick_Boyts ,

i´ll check tomorrow, thanks

for p in phases:
    room = doc.GetRoomAtPoint(pt, p)
	if room:
		output.append(p)
		break

I want to break the loop once it found a room and not continue to other phase
you can change a bit the concept yourself

1 Like

sometimes happens. I usually delete the space in front of the coding and ‘tab’ myself, it happens sometimes when I copy code from here.

1 Like