def change_sheets_name(sheet_ids, template, new): """ Change sheet number to replace by template :param sheet_ids: :param template: :param new: :return: """ data = [] for sheet_id in sheet_ids: sheet = doc.GetElement(sheet_id) sheet_number = sheet.SheetNumber if template in sheet_number: new_sheet_number = sheet.SheetNumber.replace(template, new) sheet.SheetNumber = new_sheet_number data.append('OK [#{} Sheet {}]'.format(sheet_id, repr(new_sheet_number))) logger.debug('OK [#{} Sheet {}]'.format(sheet_id, repr(new_sheet_number))) else: data.append('PASS [#{} Sheet {}]'.format(sheet_id, repr(sheet_number))) logger.debug('PASS [#{} Sheet {}]'.format(sheet_id, repr(sheet_number))) logger.info('{} Sheets was ReNumbered'.format(len(data))) return data
def get_from_win_form(): """ Получить от пользователя значение шаблона и на что заменить :return: две строки :rtype: tuple[str, str] """ components = [ Label('Введите шаблон:'), TextBox('Template', Text="A"), Label('Заменить на:'), TextBox('New_text', Text="Q"), Separator(), Button('Find and Replace') ] form = FlexForm('Title', components) form.show() if 'Template' in form.values and 'New_text' in form.values: template = form.values['Template'] new_text = form.values['New_text'] logger.info('Get from user template {} and new text {}'.format( repr(template), repr(new_text))) return template, new_text raise ElemNotFound('User canceled form')
def main(): columns = get_columns() for column in columns: try: # TODO Переписать нормально. Без try или не в этом месте create_dim_for_column(column, doc.ActiveView, K_OFFSET, K_SPACE, K_SHIFT_SPACE) except Exception as err: logger.error(err) logger.info('Create dimension for {} columns '.format(len(columns)))
def get_element_mep_systems(element): mep_system = [] if isinstance(element, DB.MEPCurve): mep_system.append(element.MEPsystem) elif isinstance(element, DB.FamilyInstance): for connector in element.MEPModel.ConnectorManager.Connectors: if connector.MEPSystem: mep_system.append(element.MEPModel.ConnectorManager.Connectors) else: logger.info("No system found in element {}".format(element)) return mep_system
def get_folder_and_prefix_by_path(path, standard_prefix): folder, name = os.path.split(path) prefix, ext = os.path.splitext(name) if prefix in [standard_prefix, '~']: prefix = '' else: logger.info('Get prefix: "{}"'.format(prefix)) logger.info('Get folder <{}>'.format(folder)) return folder, prefix
def get_selected_sheet_id(): """ Получить id Выбранных пользовтелем листов :return: Id выбранных листов :rtype: List[DB.ElementId] """ pre_selected = uidoc.Selection.GetElementIds() selected_views_id = List[DB.ElementId](pre_selected) if selected_views_id: logger.info('User select {} views'.format(len(selected_views_id))) return selected_views_id raise ElemNotFound('Please, select any sheet')
def reload_number(): result = {} count = 0 try: selected_sheet_ids = get_selected_sheet_ids() except SheetsNotSelected as err: logger.info(err.args[0]) selected_sheet_ids = [doc.ActiveView.Id] for sheet_id in selected_sheet_ids: try: str_sheet_ids = get_value_param_by_name_on_text_note_on_view( sheet_id, 'List_ids') except ElemNotFound: logger.info( 'View #{} do not have family "КЖ_Общие"'.format(sheet_id)) result[sheet_id] = '{} - do not have <КЖ_Общие>'.format( get_sheet_number_by_sheet_id(sheet_id)) continue except ParamNotFound: task_dialog(type_mes='error', msg='TextNote does not have parameter <List_ids>') continue if not str_sheet_ids: result[sheet_id] = '{} - do not have Ids'.format( get_sheet_number_by_sheet_id(sheet_id)) continue reload_number_on_view_by_str_sheet_ids(sheet_id, str_sheet_ids) result[sheet_id] = '{} - ok'.format( get_sheet_number_by_sheet_id(sheet_id)) count += 1 if result: task_dialog( type_mes='info', msg='The numbers have been updated on {} sheets'.format(count), data=result) else: task_dialog( type_mes='error', msg= 'No sheet is selected or the current active view does not have TextNote <КЖ_Общие>' )
def export_dwg(dwg_option_name, standard_prefix): result = [] views_id = get_selected_views_id() dwg_option = get_dwg_option(dwg_option_name) path_with_name = get_path(standard_prefix) folder, prefix = get_folder_and_prefix_by_path(path_with_name, standard_prefix) for view_id in views_id: name = prefix + get_name_view_by_id(view_id) col = List[DB.ElementId]([view_id]) doc.Export(folder, name, col, dwg_option) delete_pcp_file(folder, name) result.append(name) logger.debug('View #{}. Export with name "{}"'.format(view_id, name)) logger.info('Export {} files for folder: <{}>'.format( len(views_id), folder)) return result, folder
def set_param_on_text_note_on_view_by_name_and_value(view_id, name_param, value_param): """ Заполнения значение параметра у аннотации на виде :param view_id: Id вида :type view_id: DB.ElementId :param name_param: Имя параметра для заполнения :type name_param: str :param value_param: Значение параметр :type value_param: str """ text_note_name = 'GA_Примечание_КЖ' text_note = get_family_instanse_by_name_and_view_id( text_note_name, view_id) param = get_param_elem_by_name(text_note, name_param) param.Set(value_param) logger.info( 'Parameter {} on TextNote on view #{} is update on value <{}>'.format( name_param, view_id, value_param))
def user_selection_columns(): columns = uidoc.Selection.PickElementsByRectangle(ColumnFilter(), 'select columns') logger.info('User select {}'.format(len(columns))) return columns