I am trying to build a tool, helping users to identify why an element is visible in one view, but not the other. The most common reasons are easy, like closed/hidden workset, wrong design option, filters applied, category hidden etc. But I am struggling with the phase filter check.
I found, or an LLM did, the right API command, but unfortunately there is no sample in the Revit SDK on how to use it, and google has exactly one hit in the autodesk forums. Does anyone have an idea?
view_phase_param = view.get_Parameter(DB.BuiltInParameter.VIEW_PHASE)
view_phase_id = (
view_phase_param.AsElementId()
if view_phase_param else DB.ElementId.InvalidElementId
)
if view_phase_id and view_phase_id != DB.ElementId.InvalidElementId:
try:
phase_status = element.GetPhaseStatus(view_phase_id)
# ElementOnPhaseStatus.None means the element has no phase data
# and is not subject to phase filtering.
if phase_status != getattr(DB.ElementOnPhaseStatus, 'None'):
pf_param = view.get_Parameter(DB.BuiltInParameter.VIEW_PHASE_FILTER)
pf_id = pf_param.AsElementId() if pf_param else DB.ElementId.InvalidElementId
if pf_id and pf_id != DB.ElementId.InvalidElementId:
phase_filter = doc.GetElement(pf_id)
if phase_filter:
# TODO FIXME this for whatever reason doesn't work. API seems to be
# the right one according to docs.
# Errorcode is 'status is invalid for presentation query.' Printing
# 'phase_status' yields a correct ElementOnPhaseStatus.
# No Samples for this API found in SDK samples. Only web reference:
# https://forums.autodesk.com/t5/revit-api-forum/elements-project-phase-and-view-visibility/td-p/10566524
presentation = phase_filter.GetPhaseStatusPresentation(phase_status)
if presentation == DB.PhaseStatusPresentation.DontShow:
reasons.append(
"Hidden by phase filter"
" (element phase status: '{}')".format(phase_status)
)
reasons_short.append("Phase Filter")
except Exception as e:
print(e)
pass
