Add pyrevit.revit.avf — helpers for displaying values via the Analysis Visualization Framework#3487
Add pyrevit.revit.avf — helpers for displaying values via the Analysis Visualization Framework#3487Wurschdhaud wants to merge 5 commits into
pyrevit.revit.avf — helpers for displaying values via the Analysis Visualization Framework#3487Conversation
There was a problem hiding this comment.
PR Summary:
- Adds
pyrevit.revit.avf, a new helper module wrapping Revit's AVF/SpatialFieldManagerAPI to paint arbitrary numeric values onto elements/points in a view. - Provides face-selection, value display/update, primitive cleanup, and get-or-create helpers for marker/colored-surface
AnalysisDisplayStyles. - Wires the new module into
pyrevit.revit.__init__, and adds a Developer Examples demo pushbutton + bundle entry.
Review Summary:
Overall a well-documented, self-contained addition with sound transaction handling (leveraging pyRevit's existing sub-transaction support) and reasonable defensive per-element error handling. Cross-checked the AnalysisResultSchema.SetUnits API contract (non-empty/unique unit names) referenced in the module's own docstring and found two functions (update_avf_values, display_avf_values_at_points) default unit="", inconsistent with display_avf_values's "Value" default and the documented API requirement — this can throw ArgumentsInconsistentException if those functions register a schema before display_avf_values has run. Also flagged a minor Black slice-formatting nit per the repo's formatting guideline. No other correctness, security, or naming-convention issues found; IronPython 2.7 conventions (e.g. basestring) are used consistently with the rest of the codebase.
Suggestions
- Add a unit test/demo exercising update_avf_values and display_avf_values_at_points as first calls (no prior schema) to catch the empty-unit bug. Apply
Fix the empty-unit trap where update_avf_values and display_avf_values_at_points defaulted unit to '' — registering an AVF schema with an empty unit name raises ArgumentsInconsistentException from AnalysisResultSchema.SetUnits when they are the first call on a view. - Default unit to 'Value' in both functions (matching display_avf_values) - Sanitize empty unit names in _get_or_create_schema as a safety net - Add Revit-hosted regression tests exercising both functions as first calls (no prior schema) plus an explicit empty-unit case - Add DevTools 'AVF Module Tests' pushbutton to run them
|
Added regression coverage for the empty-unit trap in Since you'd already fixed the defaults to
Verified: |
This reverts commit 55852d9.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new pyrevit.revit.avf helper module that wraps Revit’s Analysis Visualization Framework (SpatialFieldManager) to make it easier for extension authors to display and update numeric overlays (markers/heatmaps) in views. It also adds a small DevTools example button to act as a smoke-test/demo for the new API.
Changes:
- Added
pyrevit.revit.avfwith helpers to create/reuse SFM + result schemas and paint/update values on elements or arbitrary XYZ points. - Exposed “get-or-create” helpers for
AnalysisDisplayStyle(marker/text and colored-surface/gradient styles). - Added an “AVF” Developer Examples button demonstrating end-to-end usage.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pyrevitlib/pyrevit/revit/avf.py |
New AVF utility module for creating schemas/styles and displaying/updating AVF values on elements/points. |
pyrevitlib/pyrevit/revit/__init__.py |
Exposes avf from the pyrevit.revit package for easier importing. |
extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/bundle.yaml |
Adds the new “AVF” example button to the DevTools panel layout. |
extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/AVF.pushbutton/script.py |
New demo script: pick element, enter value, select style, display via AVF helpers. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Description
Summary
Adds a small helper module for Revit's AVF /
SpatialFieldManagerAPI, soextension authors can paint arbitrary numeric values (KPIs, QC results,
heatmaps, counts, whatever) onto elements in a view without hand-rolling
SFM/schema/primitive bookkeeping every time.
This started as an internal tool for diagnostic/KPI overlays and I'm
proposing a generalized version for the shared lib.
What's included
get_face_facing_direction(element, direction)— returns the largestface of an element whose normal faces a given direction (typically
view.ViewDirection). Used to pick a sensible point to anchor a marker.display_avf_values(element_value_dict, view, ...)— paints a dict of{element: value}onto a view in one call; creates/reuses theSpatialFieldManagerand schema, returns primitive handles for laterupdates.
update_avf_values(primitive_dict, element_value_dict, view, ...)—cheap re-update of existing primitives (no geometry re-query).
display_avf_values_at_points(point_value_pairs, view, ...)— same ideabut for arbitrary XYZ points with no host element (e.g. a sampled grid);
automatically chunks into multiple primitives per Autodesk's documented
500-points-per-primitive guidance.
remove_avf_primitive(view, sfp_id)/clear_avf_results(view)—cleanup helpers.
get_or_create_marker_display_style(doc, style_name)— get-or-create anAnalysisDisplayStyleconfigured to show text markers.get_or_create_colored_surface_display_style(doc, style_name, ...)—get-or-create the gradient/heatmap style instead, with min/max color,
legend steps, and rounding exposed.
Known limitations
center for marker placement, which is an approximation, not a true
centroid.
use_bbox_center=Trueis the fallback for elements without usablesolid faces, but it still requires the element to have geometry
visible in the target view.
display_avf_values_at_pointschunks at 500 points/primitive perAutodesk's documented recommendation for the no-geometry overload —
not independently benchmarked here, just carried over from the docs.
Checklist
Before submitting your pull request, ensure the following requirements are met:
pipenv run black {source_file_or_directory}