Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get the room of an element

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
5461 Views, 10 Replies

Get the room of an element

Hello !

 

I'm looking to find the room of an element but i didn't find anything about that...

Do you have some clue ?

 

Regards,

Maxence

10 REPLIES 10
Message 2 of 11
naveen.kumar.t
in reply to: Anonymous

HI @Anonymous,

Are you trying to get the room , where your element is present?

If that's the case try the below code.

Element e;      
FamilyInstance Fi = e as FamilyInstance;                      
String  s =Fi.ToRoom.Name;

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 11
Anonymous
in reply to: naveen.kumar.t

Hi @naveen.kumar.t

 

Thanks for reply !

 

I just tested your code like these :

 

 

try
{

FamilyInstance fi = e as FamilyInstance;
if (fi != null && fi.Room != null)
{
string s = fi.Room.Name;
}
} catch (Exception eaze)
{
var x = 1;
}

But it seem like "FI.ROOM" is always null... but i'm sure that i have 4 room in my project 😕

 

Regards,

Maxence

 

 

Message 4 of 11
Revitalizer
in reply to: Anonymous

Hi,

 

if your element is not a FamilyInstance (and does not have ToRoom, Room, FromRoom properties), you may use

Document.GetRoomAtPoint:

 

https://forums.autodesk.com/t5/revit-api-forum/finding-the-room-for-a-certain-location/m-p/5636710

https://forums.autodesk.com/t5/revit-api-forum/get-model-groups-in-room/m-p/5904283

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 11
Anonymous
in reply to: Revitalizer

Hi @Revitalizer,

 

Thanks for reply !

 

I followed your link and i still can't get the room..

 

Here how i get my elements and then how i process to get the room

 

 FilteredElementCollector collector = new FilteredElementCollector(m_doc); 
IList<Element> m_elementsToProcess = collector.WhereElementIsNotElementType().ToElements();

//
//
//

LocationPoint lp = e.Location as LocationPoint;
if (lp != null)
{
XYZ myloc = lp.Point;
if (myloc != null)
{
Room myRoom = m_doc.GetRoomAtPoint(myloc);
if (myRoom != null)
{
string s = myRoom.Name;
}
}
}

But "myRoom" is always null..

 

Any idea ?

 

Regards,
Maxence

 

 

 

 

Message 6 of 11
Anonymous
in reply to: Anonymous

Hi !

 

Your code is correct, i just figured out that the problem was the project that the bim manager send me...

 

Thanks for help !

 

Regards,

Maxence

Message 7 of 11
Revitalizer
in reply to: Anonymous

Hi,

 

two remarks:

GetRoomAtPoint gets the room from the final Phase, so, you may use its GetRoomAtPoint(XYZ, Phase) overload to test each Phase.

Location may be slightly out of the room's volume, so make sure the point you are testing is inside the room volume and not just under it, e.g. by adding some amount to its Z value.

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 8 of 11
Anonymous
in reply to: Revitalizer

Hi,

 

For phase it's okay, we aren't using them at the moment.

 

Thanks for the type of the Z.

 

By the way, I have somes door who aren't considering in any room, so i was looking to adjust the X or Y point, but it's readonly, same for the 'Z' and i didn't find method to set it, what should I use ?

 

Regards,

Maxence

Message 9 of 11
Anonymous
in reply to: Revitalizer

I used this 

 

XYZ myloc = lp.Point;
if (myloc != null)
{
XYZ vector = new XYZ(0, 0, 1);
vector.Add(myloc);
Room myRoom = m_doc.GetRoomAtPoint(vector);

Gonna make some test 🙂

Message 10 of 11
Revitalizer
in reply to: Anonymous

Hi,

 

you cannot change an existing XYZ but create a new one, for using as input in the GetRoomAtPoint method.

 

XYZ testPoint = new XYZ(yourPoint.X, yourPoint.Y, yourPoint.Z+0.5); // add the half of a foot to Z value

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 11 of 11
Revitalizer
in reply to: Anonymous

Hi,

 

for the FromRoom/ToRoom properties, they depend on how the Families are defined (existing RoomCalculationPoint or not), plus the user can switch the logical (not the geometrical) direction via a door schedule view.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community