Skip to content

labs

Wrapper module for pyRevitLabs functionality.

Attributes

mlogger = logger.get_logger(__name__) module-attribute

config = NLog.Config.LoggingConfiguration() module-attribute

target = PyRevitOutputTarget() module-attribute

nlog_mlogger = NLog.LogManager.GetLogger(__name__) module-attribute

Classes

PyRevitOutputTarget

Bases: TargetWithLayout

NLog target to direct log messages to pyRevit output window.

Functions

Write(asyncLogEvent)

Write event handler.

Source code in pyrevitlib/pyrevit/labs.py
def Write(self, asyncLogEvent):
    """Write event handler."""
    try:
        event = asyncLogEvent.LogEvent
        level = self.convert_level(event.Level)
        if mlogger.is_enabled_for(level):
            print(self.Layout.Render(event))    #pylint: disable=E1101
    except Exception as e:
        print(e)
convert_level(nlog_level)

Convert Nlog levels to pything logging levels.

Source code in pyrevitlib/pyrevit/labs.py
def convert_level(self, nlog_level):
    """Convert Nlog levels to pything logging levels."""
    if nlog_level == NLog.LogLevel.Fatal:
        return logging.CRITICAL
    elif nlog_level == NLog.LogLevel.Error:
        return logging.ERROR
    elif nlog_level == NLog.LogLevel.Info:
        return logging.INFO
    elif nlog_level == NLog.LogLevel.Debug:
        return logging.DEBUG
    elif nlog_level == NLog.LogLevel.Off:
        return logging.DEBUG
    elif nlog_level == NLog.LogLevel.Trace:
        return logging.DEBUG
    elif nlog_level == NLog.LogLevel.Warn:
        return logging.WARNING

Functions

extract_build_from_exe(proc_path)

Extract build number from host .exe file.

Parameters:

Name Type Description Default
proc_path str

full path of the host .exe file

required

Returns:

Type Description
str

build number (e.g. '20170927_1515(x64)')

Source code in pyrevitlib/pyrevit/labs.py
def extract_build_from_exe(proc_path):
    """Extract build number from host .exe file.

    Args:
        proc_path (str): full path of the host .exe file

    Returns:
        (str): build number (e.g. '20170927_1515(x64)')
    """
    # Revit 2021 has a bug on .VersionBuild
    ## it reports identical value as .VersionNumber
    pinfo = TargetApps.Revit.RevitProductData.GetBinaryProductInfo(proc_path)
    return "{}({})".format(pinfo.build, pinfo.target) \
        if pinfo.build else "20000101_0000(x64)"