output
Provide access to output window and its functionality.
This module provides access to the output window for the currently running
pyRevit command. The proper way to access this wrapper object is through
the :func:get_output of :mod:pyrevit.script module. This method, in return
uses the pyrevit.output module to get access to the output wrapper.
Examples:
Attributes
DEFAULT_STYLESHEET_NAME = 'outputstyles.css'
module-attribute
active_stylesheet = user_config.output_stylesheet or get_default_stylesheet()
module-attribute
Classes
PyRevitOutputWindow()
Bases: object
Wrapper to interact with the output window.
The output window is an html-rendering console that scripts print to. This wrapper exposes the documented Python API for it: printing (html, markdown, code, tables, images), drawing charts, managing window geometry and icon, driving the progress bar and log panel, and saving the rendered contents.
Each wrapper binds at construction to one ScriptOutput: the running
command's own window, or the shared session window when no command is
running (e.g. session load). The binding is cached for the wrapper's
lifetime, so retaining the wrapper also retains the correct output for
deferred and modeless callbacks after the command returns.
Members not listed here are forwarded to the underlying ScriptOutput
.NET object.
Examples:
from pyrevit import script
output = script.get_output()
output.set_title('My Report')
output.print_md('### Results')
for i in range(10):
output.update_progress(i + 1, 10)
Source code in pyrevitlib/pyrevit/output/__init__.py
Attributes
window
property
PyRevitLabs.PyRevit.Runtime.ScriptConsole: Return output window object.
renderer
property
Return html renderer inside output window.
Returns:
| Type | Description |
|---|---|
WebBrowser
|
HTML renderer |
output_id
property
str: Return id of the output window.
In current implementation, Id of output window is equal to the unique id of the pyRevit command it belongs to. This means that all output windows belonging to the same pyRevit command, will have identical output_id values.
output_uniqueid
property
str: Return unique id of the output window.
In current implementation, unique id of output window is a GUID string generated when the output window is opened. This id is unique to the instance of output window.
is_closed_by_user
property
Whether the window has been closed by the user.
last_line
property
Last line of the output window.
debug_mode
property
writable
Set debug mode on output window and stream.
This will cause the output window to print information about the buffer stream and other aspects of the output window mechanism.
Functions
self_destruct(seconds)
Set self-destruct (close window) timer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
number of seconds after which window is closed. |
required |
inject_to_head(element_tag, element_contents, attribs=None)
Inject html element to current html head of the output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_tag
|
str
|
html tag of the element e.g. 'div' |
required |
element_contents
|
str
|
html code of the element contents |
required |
attribs (
|
obj: |
required |
Examples:
output = pyrevit.output.get_output()
output.inject_to_head('script',
'', # no script since it's a link
{'src': js_script_file_path})
Source code in pyrevitlib/pyrevit/output/__init__.py
inject_to_body(element_tag, element_contents, attribs=None)
Inject html element to current html body of the output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_tag
|
str
|
html tag of the element e.g. 'div' |
required |
element_contents
|
str
|
html code of the element contents |
required |
attribs (
|
obj: |
required |
Examples:
output = pyrevit.output.get_output()
output.inject_to_body('script',
'', # no script since it's a link
{'src': js_script_file_path})
Source code in pyrevitlib/pyrevit/output/__init__.py
inject_script(script_code, attribs=None, body=False)
Inject script tag into current head (or body) of the output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_code
|
str
|
javascript code |
required |
attribs (
|
obj: |
required | |
body
|
bool
|
injects script into body instead of head |
False
|
Examples:
output = pyrevit.output.get_output()
output.inject_script('', # no script since it's a link
{'src': js_script_file_path})
Source code in pyrevitlib/pyrevit/output/__init__.py
add_style(style_code, attribs=None)
Inject style tag into current html head of the output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style_code
|
str
|
css styling code |
required |
attribs (
|
obj: |
required |
Examples:
Source code in pyrevitlib/pyrevit/output/__init__.py
get_head_html()
set_title(new_title)
set_width(width)
set_height(height)
set_font(font_family, font_size)
Set window font family to the new font family and size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
font_family
|
str
|
font family name e.g. 'Courier New' |
required |
font_size
|
int
|
font size e.g. 16 |
required |
Source code in pyrevitlib/pyrevit/output/__init__.py
resize(width, height)
center()
get_title()
get_width()
get_height()
close()
close_others(all_open_outputs=False)
Close all other windows that belong to the current command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_open_outputs
|
bool
|
Close all any other windows if True |
False
|
Source code in pyrevitlib/pyrevit/output/__init__.py
hide()
show()
lock_size()
unlock_size()
freeze()
unfreeze()
save_contents(dest_file)
Save html code of the window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_file
|
str
|
full path of the destination html file |
required |
open_url(dest_url)
Open url page in output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_url
|
str
|
web url of the target page |
required |
open_page(dest_file)
Open html page in output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_file
|
str
|
full path of the target html file |
required |
update_progress(cur_value, max_value)
Activate and update the output window progress bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur_value
|
float
|
current progress value e.g. 50 |
required |
max_value
|
float
|
total value e.g. 100 |
required |
Examples:
Source code in pyrevitlib/pyrevit/output/__init__.py
reset_progress()
hide_progress()
unhide_progress()
indeterminate_progress(state)
show_logpanel()
hide_logpanel()
log_debug(message)
log_success(message)
log_info(message)
log_warning(message)
log_error(message)
set_icon(iconpath)
reset_icon()
print_html(html_str)
Add the html code to the output window.
Examples:
Source code in pyrevitlib/pyrevit/output/__init__.py
print_code(code_str)
Print code to the output window with special formatting.
Examples:
Source code in pyrevitlib/pyrevit/output/__init__.py
print_md(md_str)
Process markdown code and print to output window.
Examples:
Source code in pyrevitlib/pyrevit/output/__init__.py
print_table(table_data, columns=None, formats=None, title='', last_line_style='')
Print provided data in a table in output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_data
|
list[iterable[Any]]
|
2D array of data |
required |
title
|
str
|
table title |
''
|
columns
|
list[str]
|
list of column names |
None
|
formats
|
list[str]
|
column data formats |
None
|
last_line_style
|
str
|
css style of last row |
''
|
Examples:
data = [
['row1', 'data', 'data', 80 ],
['row2', 'data', 'data', 45 ],
]
output.print_table(
table_data=data,
title="Example Table",
columns=["Row Name", "Column 1", "Column 2", "Percentage"],
formats=['', '', '', '{}%'],
last_line_style='color:red;'
)
Source code in pyrevitlib/pyrevit/output/__init__.py
print_html_table(table_data, columns=None, formats=None, title='', last_line_style='', **kwargs)
Print provided data in a HTML table in output window.
The same window can output several tables, each with their own formatting options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_data
|
list[iterable[Any]]
|
2D array of data |
required |
title
|
str
|
table title |
''
|
columns
|
list[str]
|
list of column names |
None
|
formats
|
list[str]
|
column data formats using python string formatting |
None
|
last_line_style
|
str
|
css style of last row of data (NB applies to all tables in this output) |
''
|
**kwargs
|
extra formatting options:
|
{}
|
Examples:
data = [
['row1', 'data', 'data', 80 ],
['row2', 'data', 'data', 45 ],
]
output.print_html_table(
table_data=data,
title="Example Table",
columns=["Row Name", "Column 1", "Column 2", "Percentage"],
formats=['', '', '', '{}%'],
last_line_style='color:red;',
column_head_align_styles=["left", "left", "center", "right"],
column_data_align_styles=["left", "left", "center", "right"],
column_widths=["100px", "100px", "500px", "100px"],
column_vertical_border_style="border:black solid 1px",
table_width_style='width:100%',
repeat_head_as_foot=True,
row_striping=False
)
Source code in pyrevitlib/pyrevit/output/__init__.py
print_image(image_path)
Prints given image to the output.
Examples:
Source code in pyrevitlib/pyrevit/output/__init__.py
buttonify(uibutton, title=None)
staticmethod
Create an output-safe html button for a Revit ribbon button.
Source code in pyrevitlib/pyrevit/output/__init__.py
print_button(uibutton, title=None)
Print a Revit ribbon button as an embedded output button.
insert_divider(level='')
next_page()
Add hidden next page tag to the output window.
This is helpful to silently separate the output to multiple pages for better printing.
linkify(element_ids, title=None)
staticmethod
Create clickable link for the provided element ids.
This method, creates the link but does not print it directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_ids
|
ElementId | list[ElementId]
|
single or multiple ids |
required |
title
|
str
|
tile of the link. defaults to list of element ids |
None
|
Returns:
| Type | Description |
|---|---|
str
|
clickable link |
Examples:
output = pyrevit.output.get_output()
for idx, elid in enumerate(element_ids):
print('{}: {}'.format(idx+1, output.linkify(elid)))
Source code in pyrevitlib/pyrevit/output/__init__.py
make_chart(version=None)
make_line_chart(version=None)
:obj:PyRevitOutputChart: Return line chart object.
make_stacked_chart(version=None)
:obj:PyRevitOutputChart: Return stacked chart object.
Source code in pyrevitlib/pyrevit/output/__init__.py
make_bar_chart(version=None)
:obj:PyRevitOutputChart: Return bar chart object.
make_radar_chart(version=None)
:obj:PyRevitOutputChart: Return radar chart object.
make_polar_chart(version=None)
:obj:PyRevitOutputChart: Return polar chart object.
make_pie_chart(version=None)
:obj:PyRevitOutputChart: Return pie chart object.
make_doughnut_chart(version=None)
:obj:PyRevitOutputChart: Return doughnut chart object.
make_bubble_chart(version=None)
:obj:PyRevitOutputChart: Return bubble chart object.
Functions
docclosing_eventhandler(sender, args)
setup_output_closer()
Setup document closing event listener.
set_stylesheet(stylesheet)
Set active css stylesheet used by output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stylesheet
|
str
|
full path to stylesheet file |
required |
Source code in pyrevitlib/pyrevit/output/__init__.py
get_stylesheet()
get_default_stylesheet()
reset_stylesheet()
get_output()
:obj:PyRevitOutputWindow: Return a wrapper bound to current output.
Retain the returned wrapper when it will be used by a deferred or modeless callback after the current command returns.