Get FamilyInstances within The Room

Mohamed_Arshad
Advisor
Advisor

Get FamilyInstances within The Room

Mohamed_Arshad
Advisor
Advisor

Hello Everyone!!!!

 

     I'm facing a small issue in Filtering Family Instances within the Room. Few families not get filtered, for example

Non-Solid families are get excluded. Can anybody help me how to filter intersected 2D families also?

 

Reference Image!!!

 

arshad99_0-1660745687988.png

 

 

 

This my Code!!!

//Get Family Instance
        public List<FamilyInstance> GetFamilyInstance(Document revitDoc, Room room)
        {
            //Get Closed Shell
            GeometryElement geoEle = room.ClosedShell;

            GeometryObject geoObject = null;

            //Get Geometry Object From Geometry Element
            foreach (GeometryObject obj in geoEle)
            {
                if (obj is Solid)
                {
                    geoObject = obj;
                }
            }

            ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(geoObject as Solid);

            return new FilteredElementCollector(revitDoc)
                  .OfClass(typeof(FamilyInstance))
                  .WhereElementIsNotElementType().
                  WherePasses(elementIntersectsSolidFilter).
                  Cast<FamilyInstance>().
                  ToList();
        }

 

 

@jeremytammik @naveen.kumar.t @RPTHOMAS108 @jeremy_tammik @ricaun 

Thanks & Regards,
Mohamed Arshad K
Reply
Accepted solutions (3)
1,035 Views
8 Replies
Replies (8)

SamBerk
Advocate
Advocate

Try using the Room property:

public List<FamilyInstance> GetFamilyInstance(Document revitDoc, Room room)
{
    var elements = new FilteredElementCollector(revitDoc)
        .OfClass(typeof(FamilyInstance))
        .WhereElementIsNotElementType()
        .Cast<FamilyInstance>()
        .Where(i => IsInstanceInRoom(i, room))
        .ToList();

    return elements;    
}

bool IsInstanceInRoom(FamilyInstance instance, Room room)
{
    var isInstanceInRoom = instance.Room != null && instance.Room.Id == room.Id;
    return isInstanceInRoom;
}

 

RPTHOMAS108
Mentor
Mentor
Accepted solution

ElementIntersectsSolidFilter requires element to have solid geometry and be of category supported by interference checking.

 

Use either as @SamBerk suggests or Room.IsPointInRoom, by constructing point based on geometry location and elevate it slightly to ensure it will be found within vertical limits of room.

Mohamed_Arshad
Advisor
Advisor

Hi @SamBerk 

I checked the Room property with Revit lookup, It is always null. Do you have any other solution?

arshad99_0-1661396379395.png

 

Thanks & Regards,
Mohamed Arshad K
0 Likes

Mohamed_Arshad
Advisor
Advisor

Hi @RPTHOMAS108 
   As per your solution, I need to take a center point for the family instance and then using

IsPointInMethod() needs to ensure that the family instance is within the room limit.

If possible can you write me simple code? It will be very useful to me...Take this as a humble request

Thanks & Regards,
Mohamed Arshad K
0 Likes

jeremy_tammik
Autodesk
Autodesk
Accepted solution

The solution is very kindly given here by EatRevitPoopCad:

  

https://forums.autodesk.com/t5/revit-api-forum/how-to-determinate-if-a-toilet-belongs-to-a-room/m-p/...

  

You could also simply search this forum for IsPointInRoom to find it yourself.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

SamBerk
Advocate
Advocate
Accepted solution

@Mohamed_Arshad 

 

  • Try to use FromRoom or ToRoom property.
  • Or if you are using Phasing, you have to pass in the phase.

 

instance.get_Room(phase)
// or
instance.get_FroomRoom(phase)
//or
instance.get_ToRoom(phase)​

 

 

Or you can use this solution: https://forums.autodesk.com/t5/revit-api-forum/how-to-determinate-if-a-toilet-belongs-to-a-room/m-p/...

jeremy_tammik
Autodesk
Autodesk

Many thanks to Richard and Sam for your helpful suggestions. I summarised the conversation for posterity here:

   

https://thebuildingcoder.typepad.com/blog/2022/08/instances-in-room-and-need-for-fuzz.html#2

   

Mohamed, please let us know how exactly you end up solving this. Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

SamBerk
Advocate
Advocate

@jeremy_tammik 

Nice summary.

Thanks