Getting the face of a wall regardless of how it is drawn

Hi everyone,

Having an issue figuring out the correct side of the wall depending on how its drawn. Im using that to add dimensions to the correct side, however ive been having some issues.

im using the following code at the moment:

                    existing_line = wall.Location.Curve
                    start_point = existing_line.GetEndPoint(0)
                    end_point = existing_line.GetEndPoint(1)

                    wall_direction = (end_point - start_point).Normalize()

                    is_wall_right_to_left = wall_direction.X < 0

                    # Start with the assumption for external face
                    offset_sign = -1

                    # Adjust for wall's drawing direction (right to left)
                    if is_wall_right_to_left:
                        offset_sign *= 1

                    # Adjust for wall's flip
                    if wall.Flipped:
                        offset_sign *= 1

                    # Adjust for internal face selection
                    if selected_face == "Internal":
                        offset_sign *= -1
                        if is_wall_right_to_left:
                            offset_sign *= 1
                        if wall.Flipped:
                            offset_sign *= 1

This works fine in very simple floor plans and is correct, however with more openings and more walls it tends to have issues.

something along these lines, depending up to where you want to stop getting geometry

from pyrevit import DB, revit, script

doc = revit.doc
# collect wall instances
walls = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
for wall in walls:
    wallFaceRef = list(DB.HostObjectUtils.GetSideFaces(wall, DB.ShellLayerType.Exterior))[0]
    wallFace = wall.GetGeometryObjectFromReference(wallFaceRef)
    boundary = wallFace.EdgeLoops
    print(wallFaceRef, wallFace, boundary)
    for edgearray in boundary:
        for edge in edgearray:
            mid_point = edge.Evaluate(0.5)
            print(mid_point.X, mid_point.Y, mid_point.Z)


Thank you Jean worked like a charm. I think i might have a separate issue as it works fine with mostly drawn floorplans however if i programmatically create walls from autocad imports it still dimensions incorrectly.