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 FamilyInstances within The Room

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Mohamed_Arshad
463 Views, 8 Replies

Get FamilyInstances within The Room

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
8 REPLIES 8
Message 2 of 9
SamBerk
in reply to: Mohamed_Arshad

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;
}

 

Message 3 of 9

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.

Message 4 of 9
Mohamed_Arshad
in reply to: SamBerk

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
Message 5 of 9

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
Message 6 of 9

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
Message 7 of 9
SamBerk
in reply to: Mohamed_Arshad

@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/...

Message 8 of 9

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
Message 9 of 9
SamBerk
in reply to: jeremy_tammik

@jeremy_tammik 

Nice summary.

Thanks

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community