Redirecting print to pyRevit output window


I am trying to read the source code to understand how pyRevit works.

Looking at the PyRevitOutputWindow class in pyrevitlib > output > I see the functions to print_html(html_str) is using python’s built-in print function. Where is this function being redirected to execute in the output window?

probably in here not in python libraries

I found this method here:

def _setup_output():
    # create output window and assign handle
    out_window = runtime.types.ScriptConsole()
    runtime_info = sessioninfo.get_runtime_info()
    out_window.AppVersion = '{}:{}:{}'.format(

    # create output stream and set stdout to it
    # we're not opening the output window here.
    # The output stream will open the window if anything is being printed.
    outstr = runtime.types.ScriptIO(out_window)
    sys.stdout = outstr
    # sys.stderr = outstr
    stdout_hndlr = logger.get_stdout_hndlr() = outstr

    return out_window

Is that it?

1 Like

Yes, and the ScriptConsole() is probably defined in c#

1 Like