Face hosted family - get face of insertion

Hi,

I have a duct accessory family (inspection hatch). This is a family which is hosted on duct.
I need to get the size (A x B) of face, where the family was placed.

Unfortunately, I did not find any way to achieve that. Maybe someone was struggling with similar topic and has any advice?
Below image for reference

Better:

from pyrevit import revit 
from pyrevit import DB

element = revit.get_selection()[0]
doc = revit.doc

# Get the host face reference
element_host_face = element.HostFace
print("Reference Type:", type(element_host_face))

# Get the host element ID from the reference
host_element_id = element_host_face.ElementId
host_element = doc.GetElement(host_element_id)
print("Host Element:", host_element)
print("Host Element Type:", type(host_element))

# Now get the geometry object from the host element, not the family instance
host_face = host_element.GetGeometryObjectFromReference(element_host_face)
print("Face Type:", type(host_face))

# Get face properties
if isinstance(host_face, DB.PlanarFace):
    print("\nPlanar Face Properties:")
    print("Area:", host_face.Area)
    print("Normal:", host_face.FaceNormal)
    
    # Get bounding box for UV dimensions
    bbox = host_face.GetBoundingBox()
    u_dimension = bbox.Max.U - bbox.Min.U
    v_dimension = bbox.Max.V - bbox.Min.V
    print("U Dimension:", u_dimension)
    print("V Dimension:", v_dimension)
    
    # Get edges for actual dimensions
    edge_lengths = []
    for loop in host_face.EdgeLoops:
        for edge in loop:
            edge_lengths.append(edge.ApproximateLength)
    
    print("Edge Lengths:", edge_lengths)
    
    # If it's a rectangular face (4 edges)
    if len(edge_lengths) == 4:
        edge_lengths.sort()
        width = edge_lengths[0]  # Shorter edge
        height = edge_lengths[2]  # Longer edge
        print("\nRectangular Dimensions:")
        print("Width:", width, "feet")
        print("Height:", height, "feet")
        
elif isinstance(host_face, DB.CylindricalFace):
    print("\nCylindrical Face Properties:")
    print("Radius:", host_face.Radius)
    
print("\nOrigin point of hosted family:", element.Location.Point)

After trying my initial answer, I saw a coupe of mistakes, tried and fixed with a nice Claude prompt ;p

Dean Jean-Marc,

wow it looks it is working, I have checked code on few examples and result was very good!
I will analyze it deeper later on and adjust to my exact needs.

Thank you very much, I was struggling with this few hours yesterday without any result!
I need to start using ai.

Thanks and have a nice day.

Not necessarily. Better to understand the patterns and methods of the Revit API first

2 Likes