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
Solved! Go to Solution.
Solved by Revitalizer. Go to Solution.
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;
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
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
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
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
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
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
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 🙂
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
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
Can't find what you're looking for? Ask the community or share your knowledge.