-
-
Notifications
You must be signed in to change notification settings - Fork 465
Add TemporaryGraphics wrapper and developer example bundle #3440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Wurschdhaud
wants to merge
7
commits into
pyrevitlabs:develop
Choose a base branch
from
Wurschdhaud:new-tmpgfx
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3fc8726
new lib and developer sample: temp graphics
Wurschdhaud 96a05e2
add icon file
Wurschdhaud b144a5c
typo, unregister
Wurschdhaud a6af41c
Potential fix for pull request finding
jmcouffin 5fdd25a
Merge branch 'develop' into new-tmpgfx
Wurschdhaud fc54bd0
- do not replace active list
Wurschdhaud 3e67153
add import to init
Wurschdhaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...xtension/pyRevitDev.tab/Developer Examples.panel/TemporaryGraphics.pushbutton/bundle.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| title: "Temporary\nGraphics" | ||
| engine: | ||
| persistent: true |
7 changes: 7 additions & 0 deletions
7
....extension/pyRevitDev.tab/Developer Examples.panel/TemporaryGraphics.pushbutton/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pyrevit import revit | ||
| from pyrevit.revit.tmpgfx import ControlManager | ||
|
|
||
| cm = ControlManager(revit.doc) | ||
| cm.sync() | ||
| cm.clear_all() | ||
| cm.unregister() | ||
Binary file added
BIN
+1.09 KB
...n/pyRevitDev.tab/Developer Examples.panel/TemporaryGraphics.pushbutton/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions
116
....extension/pyRevitDev.tab/Developer Examples.panel/TemporaryGraphics.pushbutton/script.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """tmpgfx example — warning icon on a picked element.""" | ||
|
|
||
| import traceback | ||
|
|
||
| from pyrevit import revit, UI, script | ||
| from pyrevit.compat import get_elementid_value_func | ||
|
|
||
| from pyrevit.revit.tmpgfx import ControlManager, Handler | ||
|
|
||
|
|
||
| # Revit context | ||
|
|
||
|
|
||
| uidoc = revit.uidoc | ||
| doc = revit.doc | ||
|
|
||
| get_elementid_value = get_elementid_value_func() | ||
|
|
||
| # Bundle icon path — resolved once at module level | ||
|
|
||
|
|
||
| ICON_PATH = script.get_bundle_file("warning.bmp") | ||
|
|
||
| if not ICON_PATH: | ||
| raise IOError( | ||
| "warning.bmp not found in script bundle. " | ||
| "Place a 32x32 24-bit BMP named 'warning.bmp' next to script.py." | ||
| ) | ||
|
Wurschdhaud marked this conversation as resolved.
|
||
|
|
||
|
|
||
| # Custom handler | ||
| class WarningHandler(Handler): | ||
| """Shows a TaskDialog with element info when a warning icon is clicked.""" | ||
|
|
||
| def __init__(self): | ||
| Handler.__init__( | ||
| self, | ||
| name="pyRevit Warning Icon Handler", | ||
| description="Displays element info on warning icon click", | ||
| vendor_id="pyRevit", | ||
| ) | ||
| # keep a doc reference for element lookup | ||
| self._doc = doc | ||
|
|
||
| def on_click(self, index, payload): | ||
| """Show element name and Id when the warning icon is clicked. | ||
|
|
||
| Args: | ||
| index (int): Control index that was clicked. | ||
| payload: The DB.Element stored when the control was created. | ||
| """ | ||
| try: | ||
| if payload is None: | ||
| UI.TaskDialog.Show( | ||
| "Warning Icon Clicked", | ||
| "Control index: {}\n(no element linked)".format(index), | ||
| ) | ||
| return | ||
|
|
||
| elem = payload | ||
| UI.TaskDialog.Show( | ||
| "Warning Icon Clicked", | ||
| "Element: {}\nId: {}".format( | ||
| elem.Name, | ||
| get_elementid_value(elem.Id), | ||
| ), | ||
| ) | ||
| except Exception: | ||
| print(traceback.format_exc()) | ||
|
|
||
|
|
||
| # Pick an element | ||
|
|
||
|
|
||
| elem = revit.pick_element() | ||
| if not elem: | ||
| script.exit() | ||
|
|
||
| bbox = elem.get_BoundingBox(None) | ||
|
|
||
| if not bbox: | ||
| UI.TaskDialog.Show("Error", "Selected element has no bounding box.") | ||
| script.exit() | ||
|
|
||
| center = (bbox.Min + bbox.Max) * 0.5 | ||
|
|
||
|
|
||
| # Create handler + manager, place the control | ||
|
|
||
|
|
||
| handler = WarningHandler() | ||
| mgr = ControlManager(doc, handler=handler) | ||
|
|
||
| active_view = uidoc.ActiveView | ||
|
|
||
| control_index = mgr.add_control( | ||
| icon_path=ICON_PATH, | ||
| position=center, | ||
| view=active_view, | ||
| payload=elem, | ||
| ) | ||
|
|
||
| if control_index == -1: | ||
| print("Failed to create in-canvas control.") | ||
| script.exit() | ||
|
|
||
| print( | ||
| "Warning icon placed (control index: {}, element: '{}', id: {}).".format( | ||
| control_index, | ||
| elem.Name, | ||
| get_elementid_value(elem.Id), | ||
| ) | ||
| ) | ||
| print("Click the icon in the canvas to see element info.") | ||
| print("Controls in active view: {}".format(mgr.control_count(active_view))) | ||
Binary file added
BIN
+3.65 KB
...xtension/pyRevitDev.tab/Developer Examples.panel/TemporaryGraphics.pushbutton/warning.bmp
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.