Ejemplo n.º 1
0
def _produce_ui_stacks(ui_maker_params):
    """

    Args:
        ui_maker_params (UIMakerParams): Standard parameters for making ui item
    """
    parent_ui_panel = ui_maker_params.parent_ui
    stack_parent = ui_maker_params.parent_cmp
    stack_cmp = ui_maker_params.component
    ext_asm_info = ui_maker_params.asm_info

    # if sub_cmp is a stack, ask parent_ui_item to open a stack
    # (parent_ui_item.open_stack).
    # All subsequent items will be placed under this stack. Close the stack
    # (parent_ui_item.close_stack) to finish adding items to the stack.
    try:
        parent_ui_panel.open_stack()
        mlogger.debug('Opened stack: %s', stack_cmp.name)

        if HOST_APP.is_older_than('2017'):
            _component_creation_dict[SPLIT_BUTTON_POSTFIX] = \
                _produce_ui_pulldown
            _component_creation_dict[SPLITPUSH_BUTTON_POSTFIX] = \
                _produce_ui_pulldown

        # capturing and logging any errors on stack item
        # (e.g when parent_ui_panel's stack is full and can not add any
        # more items it will raise an error)
        _recursively_produce_ui_items(
            UIMakerParams(parent_ui_panel,
                          stack_parent,
                          stack_cmp,
                          ext_asm_info,
                          ui_maker_params.create_beta_cmds))

        if HOST_APP.is_older_than('2017'):
            _component_creation_dict[SPLIT_BUTTON_POSTFIX] = \
                _produce_ui_split
            _component_creation_dict[SPLITPUSH_BUTTON_POSTFIX] = \
                _produce_ui_splitpush

        try:
            parent_ui_panel.close_stack()
            mlogger.debug('Closed stack: %s', stack_cmp.name)
            return stack_cmp
        except PyRevitException as err:
            mlogger.error('Error creating stack | %s', err)

    except Exception as err:
        mlogger.error('Can not create stack under this parent: %s | %s',
                      parent_ui_panel, err)
Ejemplo n.º 2
0
 def create_splitpush_button(self, item_name, icon_path,
                             update_if_exists=False):
     if self.itemdata_mode and HOST_APP.is_older_than('2017'):
         raise PyRevitUIError('Revits earlier than 2017 do not support '
                              'split buttons in a stack.')
     else:
         self._create_button_group(UI.SplitButtonData, item_name, icon_path,
                                   update_if_exists)
         self.ribbon_item(item_name).sync_with_current_item(False)
Ejemplo n.º 3
0
def toggle_category_visibility(view, subcat, hidden=None):
    if HOST_APP.is_older_than(2018):
        if hidden is None:
            hidden = not view.GetVisibility(subcat.Id)
        view.SetVisibility(subcat.Id, hidden)
    else:
        if hidden is None:
            hidden = not view.GetCategoryHidden(subcat.Id)
        view.SetCategoryHidden(subcat.Id, hidden)
Ejemplo n.º 4
0
            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


# activate binding resolver
if not EXEC_PARAMS.doc_mode:
    if HOST_APP.is_older_than(2019):
        TargetApps.Revit.PyRevitBindings.ActivateResolver()

    # configure NLog
    #pylint: disable=W0201
    config = NLog.Config.LoggingConfiguration()
    target = PyRevitOutputTarget()
    target.Name = __name__
    target.Layout = "${level:uppercase=true}: [${logger}] ${message}"
    config.AddTarget(target)
    config.AddRuleForAllLevels(target)
    NLog.LogManager.Configuration = config

    for rule in NLog.LogManager.Configuration.LoggingRules:
        rule.EnableLoggingForLevel(NLog.LogLevel.Info)
        rule.EnableLoggingForLevel(NLog.LogLevel.Debug)
Ejemplo n.º 5
0
import csv

from System.Collections.Generic import List

from Autodesk.Revit.DB import (
    FilteredElementCollector,
    UnitUtils,
    Document,
    MEPSize,
    Material,
)
from Autodesk.Revit.DB.Plumbing import PipeSegment, PipeScheduleType

import rpw
from pyrevit import script, forms, revit, HOST_APP
if HOST_APP.is_older_than(2022):
    from Autodesk.Revit.DB import DisplayUnitType
    LENGTH_UNIT = DisplayUnitType.DUT_MILLIMETERS
else:
    from Autodesk.Revit.DB import UnitTypeId
    LENGTH_UNIT = UnitTypeId.Millimeters

doc = __revit__.ActiveUIDocument.Document  # type: Document
logger = script.get_logger()


def read_csv(csv_path):
    size_set = List[MEPSize]()
    with open(csv_path, "rb") as csvfile:
        reader = csv.reader(csvfile, delimiter="\t")
        headers = next(reader)
Ejemplo n.º 6
0
 def import_config_length(self, name):
     length = float(self._config.get_option(name, '1'))
     if HOST_APP.is_older_than(2022):
         return UnitFormatUtils.Format(UNITS, length_unit, length, True, True)
     else:
         return UnitFormatUtils.Format(UNITS, length_unit, length, True)