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!!!
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
Solved! Go to Solution.
Solved by SamBerk. Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Solved by RPTHOMAS108. Go to Solution.
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;
}
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.
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
The solution is very kindly given here by EatRevitPoopCad:
You could also simply search this forum for IsPointInRoom to find it yourself.
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/...
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!