tmpgfx
TemporaryGraphics wrapper and utilities.
Usage::
from pyrevit.revit.tmpgfx import ControlManager, Handler
class MyHandler(Handler):
def on_click(self, index, payload):
# payload is whatever you passed to add_control()
TaskDialog.Show("Clicked", str(payload))
mgr = ControlManager(doc, handler=MyHandler())
mgr.add_control(icon_path, position, view, payload=my_elem)
# ... later ...
mgr.clear(view)
mgr.unregister()
Attributes
get_elementid_value = get_elementid_value_func()
module-attribute
Classes
Handler(guid=None, name='pyRevit TemporaryGraphics Handler', description='Handles in-canvas control click events', vendor_id='pyRevit', register=True)
Bases: ITemporaryGraphicsHandler
Base ITemporaryGraphicsHandler implementation.
Subclass and override :meth:on_click to react to control clicks.
The handler is automatically registered with the external service on
construction unless register is False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guid
|
Guid
|
Stable GUID for this handler. A fresh random GUID is generated
when |
None
|
name
|
str
|
Human-readable handler name visible in the Revit service registry.
Defaults to |
'pyRevit TemporaryGraphics Handler'
|
description
|
str
|
Short description shown in the service registry.
Defaults to |
'Handles in-canvas control click events'
|
vendor_id
|
str
|
Vendor identifier string. Defaults to |
'pyRevit'
|
register
|
bool
|
Register the handler on construction. Defaults to |
True
|
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
Attributes
guid = Guid.NewGuid() if guid is None else guid
instance-attribute
name = name
instance-attribute
description = description
instance-attribute
vendor_id = vendor_id
instance-attribute
Methods:
GetName()
GetDescription()
GetVendorId()
GetServerId()
GetServiceId()
OnClick(command_data)
Dispatch a click event to :meth:on_click.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_data
|
InCanvasControlClickCommandData
|
Revit-supplied click data; |
required |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
on_click(index, payload)
Called when an in-canvas control is clicked.
Override in a subclass to implement custom click behaviour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The control index as assigned by the manager. |
required |
payload
|
The arbitrary object that was associated with the
control via :meth: |
required |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
register()
Register this handler with the TemporaryGraphicsHandlerService.
Safe to call multiple times; a previously registered instance with the same GUID is removed first.
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
unregister()
Remove this handler from the TemporaryGraphicsHandlerService.
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
ControlManager(doc, handler=None)
Bases: object
Manages in-canvas controls for one Revit document.
Wraps :class:DB.TemporaryGraphicsManager and keeps controls organised
per view so they can be cleared selectively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The active Revit document. |
required |
handler
|
Handler
|
A :class: |
None
|
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
Attributes
handler
property
The :class:Handler instance owned by this manager.
Methods:
add_control(icon_path, position, view, payload=None)
Place an in-canvas control icon at position in view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
icon_path
|
str
|
Absolute path to a BMP icon file (24-bit, recommended 32 x 32 or 64 x 64 px for consistent display). To achieve a "transparent" background color effect over the provided bitmap, the bitmap should use color RGB(0, 128, 128) as its background and it will be cleared during rendering by Revit. |
required |
position
|
XYZ
|
World-space position for the control anchor point. |
required |
view
|
View
|
The view in which the control should appear. |
required |
payload
|
object
|
Arbitrary Python object forwarded to
:meth: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
The control index assigned by Revit, or |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
remove_control(index, view)
Remove a single in-canvas control by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The control index returned by :meth: |
required |
view
|
View
|
The view the control belongs to. |
required |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
clear(view)
Remove all in-canvas controls that belong to view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
View
|
The view whose controls should be cleared. |
required |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
clear_all()
Remove every in-canvas control across all views.
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
refresh()
Request a view refresh to make newly added controls visible.
unregister()
Unregister the handler and remove all controls.
Call this during script cleanup to avoid stale handlers persisting across pyRevit reloads.
control_count(view=None)
Return the number of active controls, optionally scoped to view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
View
|
When provided, count only controls in that view.
When |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
Number of active controls. |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
get_all_indices()
Return every control index currently live in the Revit manager.
Delegates directly to :meth:DB.TemporaryGraphicsManager.GetAll so
the result reflects the actual Revit state, not the internal dict.
Returns:
| Type | Description |
|---|---|
|
list[int]: Live control indices, or an empty list on failure. |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
sync()
Reconcile the internal dict against the live Revit state.
Any index returned by :meth:DB.TemporaryGraphicsManager.GetAll that
is not already tracked is added to the None sentinel bucket. This
lets you recover control over indices that were registered by a
previous script run (e.g. after a pyRevit reload) without knowing
which view they belong to.
Indices that are tracked internally but absent from Revit are pruned so the dict does not grow stale.
Returns:
| Type | Description |
|---|---|
|
tuple[list[int], list[int]]:
|
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
remove_all_untracked()
Remove every control Revit knows about that is not in the dict.
Useful after a script reload when you want a guaranteed clean slate without caring about preserving any existing controls.
Returns:
| Type | Description |
|---|---|
|
list[int]: Indices that were removed. |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
set_visibility(index, visible)
Show or hide a single in-canvas control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The control index to update. |
required |
visible
|
bool
|
|
required |
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
set_visibility_all(visible, view=None)
Show or hide controls, optionally scoped to view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visible
|
bool
|
|
required |
view
|
View
|
When provided, only controls tracked under that view are
affected. When |
None
|
Source code in pyrevitlib/pyrevit/revit/tmpgfx.py
update_control(index, icon_path, position)
Update the icon or position of an existing in-canvas control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The control index to update. |
required |
icon_path
|
str
|
Absolute path to the replacement BMP icon file. |
required |
position
|
XYZ
|
New world-space anchor position. |
required |