Pick faces/edges of walls and openings

Hi everyone,

I am trying to make a selector that allows user to select levels/edges/faces for height dimensioning but i cant seem to get the selector to work for wall faces perpendicular to the view

# Import Revit and pyRevit modules
from pyrevit import revit, DB, UI
from pyrevit import script

# Get the current document
doc = revit.doc
uidoc = revit.uidoc

# Check if the active view is a section view
active_view = doc.ActiveView
if not isinstance(active_view, DB.ViewSection):
    script.exit("This script only works in section views.")

# Create a custom selection filter for all faces, edges, and element lines
class AllFacesAndEdgesSelectionFilter(UI.Selection.ISelectionFilter):
    def AllowElement(self, elem):
        # Allow all elements that are not hidden in the active view
        if elem.IsHidden(active_view):
            return False
        return   # Allow all visible elements

    def AllowReference(self, reference, point):
        # Allow all geometric references like faces, edges, etc., even if perpendicular
        reference_types = [
            DB.ElementReferenceType.REFERENCE_TYPE_NONE,
            DB.ElementReferenceType.REFERENCE_TYPE_LINEAR,
            DB.ElementReferenceType.REFERENCE_TYPE_SURFACE,
            DB.ElementReferenceType.REFERENCE_TYPE_FOREIGN,
            DB.ElementReferenceType.REFERENCE_TYPE_INSTANCE,
            DB.ElementReferenceType.REFERENCE_TYPE_CUT_EDGE,
            DB.ElementReferenceType.REFERENCE_TYPE_MESH
        ]
        if reference.ElementReferenceType in reference_types:

            return True
        return False

# Prompt the user to select any visible elements or faces
selection_message = "Select visible edges, faces, or lines in the view."

# Allow the user to select multiple geometry elements using the custom filter
try:
    all_faces_filter = AllFacesAndEdgesSelectionFilter()
    references = uidoc.Selection.PickObjects(
        UI.Selection.ObjectType.Element, all_faces_filter, selection_message)
    
    if not references:
        script.exit("No geometry was selected.")
    
    # Extract selected elements and display their information
    selected_elements = []
    for ref in references:
        element = doc.GetElement(ref.ElementId)
        selected_elements.append(element)

    # Output the selected elements' information
    output = script.get_output()
    output.print_table(
        table_data=[(element.Id, str(element)) for element in selected_elements],
        title="Selected Elements",
        columns=["Element ID", "Element Details"]
    )

except Exception as e:
    script.exit("Selection canceled or error occurred: {}".format(e))

I tried using the ISelectionfilter but i can only select elements this way, not edges/faces etc

On my phone but it should look like

faces = uidoc.Selection.PickObjects(ObjectType.Face, "Select faces"

Have a look at pyrevit code, it usually contains snippets that get you going

1 Like

Thank you! This worked :slight_smile:

1 Like