def make_old_format(self, result, old_format_path): # echo(to_old_format) dir_path = old_format_path panel = result["value"] old_format = { "mark": [panel["mark"]], "components": panel["components"]["componentVals"], "details": panel["details"], "series": panel["series"] } for i in self.windows: old_format["components"].append(i.to_old_format()) try: string = json.dumps(old_format, sort_keys=True, indent=4, ensure_ascii=False) string = string.replace('"Body"', '"body"') string = string.replace('"Window"', '"window"') string = string.replace('"Connection"', '"connection"') string = string.replace('"Balcony"', '"window"') string = string.replace('"x"', '"X"') string = string.replace('"y"', '"Y"') string = string.replace('"z"', '"Z"') self.request_to_coloristic_server(json.loads("[" + string + "]")) except: echo("{} не выгружена в базу колористики".format(self)) pass
def rev_panel(self): """Находит ревитовскую панель и возвращает ее""" echo(self.parent.name) for panel in __revit__.GetRibbonPanels(self.parent.name): echo(panel) if panel.Title == self.name: return panel
def get_all_tabs(sender=None, e=None): config_path = os.path.join( os.environ["PROGRAMDATA"], r"Autodesk\Revit\Addins\2019\RedBim\config.json") with open(config_path, "r") as f: data = json.load(f) f.close() all_tab = [] script_path = DIR_SCRIPTS # echo("Получаем имена всех вкладок с " + script_path) files = os.listdir(script_path) # echo(files) # echo("____________________", "Создаем все вкладки") # echo('\n') # test = False for file in files: # if not test: # message(os.path.join(script_path, file)) # test = True os.path.isdir(os.path.join(script_path, file)) is_tab = re.search(r".tab$", file) if is_tab: # if section == "all" or section in file or ("test" in file and developer): for i in data: if i["name"] == file: if i["active"]: all_tab.append( RB_Tab(file, script_path, childs=i["childs"])) break else: all_tab.append(RB_Tab(file, script_path)) # echo('\n') if not all_tab: echo("Папок со скриптами нет") return all_tab
def __init__(self, rvt_link_doc, start_point): self.rvt_link_doc = rvt_link_doc self.start_point = start_point self.sections = {} if start_point is None: echo("""Не найдена стартовая точка проекта в {}. Необходимо, как минимум, две пересекающахися глобальных оси""".format(self))
def check_parameters(self): app = __revit__.Application shared_par_file = app.OpenSharedParameterFile() pb = self.doc.ParameterBindings for i in shared_par_file.Groups: for definition in i.Definitions: if definition.Name in self.parameters.keys( ) and not self.parameters[definition.Name]["in_family"]: param = self.parameters[definition.Name] doc_cats = [ self.doc.Settings.Categories.get_Item(i) for i in param["categoryes"] ] if pb.Contains(definition): parameter_bind = pb.Item[definition] change_cats = [] for cat in doc_cats: if not parameter_bind.Categories.Contains(cat): parameter_bind.Categories.Insert(cat) change_cats.append(cat.Name) if change_cats: echo("Для параметра {} добавлены категории {}". format(definition.Name, ", ".join(change_cats))) pb.ReInsert(definition, parameter_bind) else: cat_set = app.Create.NewCategorySet() for cat in doc_cats: cat_set.Insert(cat) nib = app.Create.NewInstanceBinding(cat_set) pb.Insert(definition, nib, param["group"]) echo("Добавлен параметр {} для категорий {}".format( definition.Name, ", ".join([i.Name for i in doc_cats])))
def create_PPBD(self): """Создает экземпляр PPBD.""" echo("Создаем экземпляр PPBD " + self.name) echo("Путь " + self.script_path) return PyPushButtonData(self.name + str(self.PB_count), self.name + str(self.PB_count), self.script_path, __revit__, START_SCRIPT).Finish()
def parameter_is_exists(self, parameters): "Проверяет наличие параметров у элемета." all_ok = True for i in parameters: if not self.get_param(i): all_ok = False echo("Не найден параметр {}".format(i)) return all_ok
def __init__(self, panel, doc=None, analys_geometry=False, old_format=None, develop=False, geometrical=False): super(Precast_panel, self).__init__(panel, doc, analys_geometry=analys_geometry) self.develop = develop self.obj = {} self.is_analysed = False self.geometrical = geometrical # Необходимо, чтобы ID определился при создании панели. Для монтажек self.Id all_panel_parameters = [ self.mass_parameter_name, self.volume_parameter_name, self.series_parameter_name, self.facade_type_parameter_name, self.mark_prefix_parameter_name, self.mark_sub_prefix_parameter_name, self.construction_type_parameter_name, self.advance_mark_parameter_name, self.mark_parameter_name, self.system_mark_parameter_name, "JSON" ] try: # echo(geometrical) if self.parameter_is_exists(all_panel_parameters): self.series_param = self[self.series_parameter_name] self.mark_prefix_param = self[self.mark_prefix_parameter_name] # Костыль, который меняет тройку на букву З if self.mark_prefix_param: self.mark_prefix_param = self.mark_prefix_param.replace( "ЗНС", "3НС") self.facade_type_param = self[self.facade_type_parameter_name] if self[self.facade_type_parameter_name] else "" self.mark_sub_prefix_param = self[self.mark_sub_prefix_parameter_name] if self[self.mark_sub_prefix_parameter_name] else "" self.construction_type_param = self[self.construction_type_parameter_name] if self[self.mark_sub_prefix_parameter_name] else "" if not self.facade_type_param and geometrical: echo("Не указан FacadeType") if not self.mark_sub_prefix_param and geometrical: echo("Не указан SubPrefix") if not self.construction_type_param and geometrical: echo("Не указан ConstructionType") if self.analys_geometry and self.geometrical: self.disassemble() self.make_analys_geometry() self.set_windows_to_panel() self.add_ifc_parameter() self.add_indastry_parameter() # self.assambly = self.make_assambly() else: echo( "Ошибки в получении параметров у панели {} {}".format(self, sys.exc_info()[1])) except: echo("Ошибка в панели {} {}".format(self, sys.exc_info()[1]))
def calculate_symbol(self, str_to_parse): """ Вычисления производимые в строках. Для начала находим все параметры регулярным выражением От параметров откидываем квадратные скобки. Заменяем пармаетры на числа Все числа преобразовываем из строки в float Находим все, что нужно умножить или поделить. В цикле выполняем умножение. То, что перемножили делаем None Результат записываем во втоой элемент Очищаем массив от None Как с умножением поступаем с сложением/вычитанием Возвращаем результат Если всего один элемент - возвращаем его """ try: meta_templ_params = "([^A-Za-zА-Яа-я_][0-9\.]+[^A-Za-zА-Яа-я_])|(^[0-9\.]+[^A-Za-zА-Яа-я_])|([^A-Za-zА-Яа-я_][0-9\.]+$)|((\*)|(\-)|(\/)|(\+))|(\[[А-Яа-яA-Za-z\.\s_]+\])" meta_templ_params = re.compile(meta_templ_params) params = [[j for j in i if j][0].strip().lstrip("[").rstrip("]") for i in meta_templ_params.findall(str_to_parse)] params = [(self[i] if self[i] else i) for i in params] params = [(float(i) if isinstance(i, str) and i.replace(".", "").isnumeric() else i) for i in params] multiple = [] for key, par in enumerate(params): if par == "*" or par == "/": multiple.append((key - 1, key, key + 1, params[key - 1], par, params[key + 1])) for i in multiple: if i[4] == "*": res = i[3] * i[5] elif i[4] == "/": res = i[3] / i[5] params[i[1]] = res params[i[0]] = None params[i[2]] = None params = [i for i in params if i is not None] result = 0 for key, i in enumerate(params): if key == 0: result = i elif i == "+": result += params[key + 1] elif i == "-": result -= params[key + 1] result = round(result) except: result = '"ошибка"' if self.is_echo: echo("Ошибка в формировании параметра в {}".format(self)) return result
def create_panel(self): """Создаем ревитовскую панель и сохраняем ее в sys_tab.""" nrp = self.panel_is_exist if not nrp: echo("Пытаемся создать панель " + self.name) nrp = __revit__.CreateRibbonPanel(self.parent.name, self.name) return nrp echo("Панель " + self.name + " существует")
def __init__(self, direct, parent, is_user=False): """direct, parent, is_user.""" echo('***********************') self.is_user = is_user self.pushbutton = [] # Все кнопки в панели depricated self.path = direct self.parent = parent self.sys_panel = self.create_panel() # Ревитовский объект с панелью self.controls = self.control_finder() # Все кнопки в панели
def finder_iterator_by_name(arr, name): if not isinstance(arr, list): arr = list(arr) new_arr = [] name = name.lower() for el in arr: if name in el.Name.lower(): echo(name, el.Name.lower()) new_arr.append(el) return new_arr
def __init__(self, direct, parent, is_user=False): """Инициализируем direct, parent, is_user.""" self.is_user = is_user self.path = direct self.parent = parent echo("Начинаем создание кнопки " + self.name) panel = self.parent.sys_panel if panel: self.__class__.PB_count = self.__class__.PB_count + 1 self.get_button_or_create() self.add_image()
def json(self): if not hasattr(self, "_json"): echo(self) echo("Состоит из:") res_obj = [{ "point": self.make_xyz(XYZ()), "type": "Body", "solids": [] }] for key in self.plan.keys(): obj = { "layer": key, "cutting": False, "plan": [self.make_xyz(i, nullable_z=True) for i in self.plan[key]["points"]], "profile": [self.make_xyz(i, nullable_x=True) for i in self.profile[key]["points"]], "point": self.make_xyz(XYZ(self.plan[key]["point"].X, self.plan[key]["point"].Y, self.profile[key]["point"].Z)), } res_obj[0]["solids"].append(obj) for i in self.holes: res_obj.append(i.define_json()) # echo(self.mark_prefix_param) # self.facade_type_param = self.facade_type_param if self.facade_type_param else "" res_obj = { "series": self.series_param, "markPrefix": self.mark_prefix_param + self.facade_type_param, "markSubPrefix": self.mark_sub_prefix_param, "constructionType": self.construction_type_param, "handle": self.element.Id.IntegerValue, "components": { "componentVals": res_obj, "componentRefs": [] }, "details": [] } for i in self.windows: echo(i, "", i.mesure) res_obj["components"]["componentRefs"].append(i.define_json()) for i in res_obj["components"]["componentVals"]: i["solids"].sort(key=lambda x: x['layer']) # sel = __revit__.ActiveUIDocument.Selection # els = List[ElementId]() for i in self.embedded_parts: # els.Add(i.element.Id) echo(i.tag, " ", i.mesure, " ", i.Id) res_obj["details"].append(i.define_json()) # sel.SetElementIds(els) self._json = res_obj echo(" ") return self._json
def find_panel(self): """Ищем панели в данной вкладке.""" files = os.listdir(self.path) for i in files: if os.path.isdir(os.path.join(self.path, i)): line = i pattern = r'panel$' result = re.search(pattern, line) if result: panel_path = os.path.join(self.path, i) echo("Создаем панель по пути " + panel_path) new_panel = RB_Panel(panel_path, self) self.panels.append(new_panel)
def find_section(self, point=None, direction=None, x=None, y=None): solids = self.concate_all_elements_by_materials() if not solids: echo( "У панели {} не найден ни один материал. \nВозможно не назначен параметр BDS_LayerNumber у материалов.\n" .format(self)) all_faces = {} # Находим поверхности, которые находятся на пересечении for key, solid in solids.items(): # echo(key) if not key: continue face = solid.get_face_in_point(origin=point, normal=direction) if face: all_faces[key] = face # # преобразовываем поверхности в линии lines_dict = {} for key, faces in all_faces.items(): lines_dict.setdefault(key, []) for face in faces: # if key == 2: # self.print_face(face) for eloop in face.EdgeLoops: for line in eloop: line = line.AsCurve() line = self.project_line_on_plane(line, origin=point, normal=direction) if line: lines_dict[key].append(line) # # # Оставить линии, только соответствующие x и y points = {} # echo(points) for key, lines in lines_dict.items(): lines = self.only_ortogonal_lines(lines, x, y) cur_points = self.find_intersect(lines) self.remove_unuse_points(cur_points, solids[key], direction, x, y) # if key == 2: # for point in cur_points: # Line_printer.print_arc(point, radius=0.02) # echo(key) # echo(cur_points) result = [] if cur_points: self.clockwise(cur_points, result, x=x, y=y) else: raise Exception("При анализе сечения были отброшены все точки") points[key] = result return points
def get_parameter_form_project_info(self, par_name): "Получение параметра из информации о проекте." if not hasattr(self, "_project_info"): self._project_info = FilteredElementCollector(self.doc).OfCategory( BuiltInCategory.OST_ProjectInformation).FirstElement() par = self._project_info.LookupParameter(par_name) if par is None: echo("{} не найден в проекте".format(par_name)) return None val = par.AsString() if not val: echo("{} не заполнен в проекте".format(par_name)) return None return val
def __init__(self, doc, analys="document"): self.doc = doc self.childs = [] if analys == "document": self.view_by_types() self.make_schedulde_complex() self.make_sheet_complex() self.make_schedulde_complex() self.make_view_complex() self.make_template_complex() els = list(self.obj.keys()) els.sort(reverse=True) for i in els: echo("{}: {}".format(i, self.obj[i]))
def structural_framing(self): if not hasattr(self, "_structural_framing"): eror_elements = [] self._structural_framing = [] for doc, count in self.docs.items(): fec = FilteredElementCollector(doc).OfCategory( BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType() for el in fec.ToElements(): par = self.get_parameter(el, par_names["КлассЧисло"]) if par and par.AsDouble(): new_el = StructuralFraming(el, self.csv_dict, count=count) if not new_el.error: self._structural_framing.append(new_el) else: eror_elements.append(new_el) if len(eror_elements): echo("Ошибочные элементы в проекте в количестве {}.".format(len(eror_elements))) for i in eror_elements: echo(i.error, " ", i.doc_name()) return self._structural_framing
def create_instalation_plan(self): "Создание файлов монтажного плана." # self.path_to_save = self.select_path() self.start_point, self.start_grids = self.find_start_point_and_grids() # echo(self.start_point, self.start_grids) self.recalculate_grid_origins(self.grids, self.start_point, self.start_grids) Instalation_plan_link.create(self.rvt_links, self.start_point) global_obj = Instalation_plan_link.find_panels_in_links(to_old=True) axis = self.grids_to_dict(self.grids, elevation=False) axis = [{ "position": i["origin"], "rotation": i["direction"], "local": i["localName"], "global": i["globalName"], } for i in axis] common_data = { "blockName": self.block_name, "blockCode": self.block_code, "buildingName": self.building_name, "sectionName": None, "fullName": None, "assemblyData": {} } old_format_obj = Instalation_plan_link.all_panel_dict_old( global_obj, common_data, axis) # echo(json.loads(self.get_block_from_db())) # echo(json.dumps([res], sort_keys=True, indent=4, ensure_ascii=False)) result = json.loads(self.push_build_assambly_to_db(old_format_obj)) if result: res_str = "Не найдены панели" for panel in result: res_str += "\n{}".format(panel) res_str += "\n" + "Монтажный план не загружен." echo(res_str) else: echo("Монтажный план загружен в сервис") self.print_result_upload(old_format_obj)
def set_coloristic_tag(self, obj): """ Устанавливает коллористические марки. Открывает файл с закрытыми рабочими наборами. Для этого создается конфиг open_opt Проходим по всем документам и панелям, которые переданы в obj Выгружаем связь. Открываем документ. Проверяем можно ли вносить изменения в документ. Пробуем внести изменения. Проходим по всем панелям и уровням. Получаем в документе связи панель по ID. Проходим по всем уровням. Для каждой колористик Tag устанавливаем марку по уровню. Если файл общий. Синхронизироваться. Если файл не общий - просто сохранить. В противном случае закрыть документ """ workset_config_option = WorksetConfigurationOption.CloseAllWorksets workset_config = WorksetConfiguration(workset_config_option) open_opt = OpenOptions() open_opt.SetOpenWorksetsConfiguration(workset_config) app = self.doc.Application for doc, panels in obj.items(): title = doc.Title m_p = ModelPathUtils.ConvertUserVisiblePathToModelPath( doc.PathName) rvt_type = self.rvt_docs[doc] rvt_type.Unload(None) cur_doc = app.OpenDocumentFile(m_p, open_opt) if not cur_doc.IsReadOnly: try: with Transaction(cur_doc, "Вносим изменения") as t: t.Start() for panel, levels in panels.items(): panel = cur_doc.GetElement(ElementId(panel.Id)) for level, mark in levels.items(): level = level if len( level) > 1 else "0" + level panel.LookupParameter( "BDS_ColoristicsTag_Floor" + level).Set(mark) t.Commit() if cur_doc.IsWorkshared: twc_opts = TransactWithCentralOptions() swc_opts = SynchronizeWithCentralOptions() swc_opts.SetRelinquishOptions(RelinquishOptions(True)) swc_opts.Comment = "Атоматическая синхронизация КЖС" cur_doc.SynchronizeWithCentral(twc_opts, swc_opts) cur_doc.Close(True) except: echo(sys.exc_info()[1]) cur_doc.Close(False) else: echo("Файл {} доступен только для чтения".format(title)) cur_doc.Close(False) rvt_type.Load() echo("Обработали связь {}".format(title))
def create_grid_plan(self): """ Создать файл осей. """ # self.path_to_save = self.select_path() self.start_point, self.start_grids = self.find_start_point_and_grids() self.recalculate_grid_origins(self.grids, self.start_point, self.start_grids) if self.block_code and self.block_name and self.building_name: res = { "blockName": self.block_name, "blockCode": self.block_code, "buildingName": self.building_name, "gridsData": self.grids_to_dict(self.global_grids) } if len([i for i in res["gridsData"]["Grids"] if i["globalName"] ]) < 4: echo("Осей в файле меньше 4") elif len(res["gridsData"]["Levels"]) < 2: echo("Осей в файле меньше 2") else: if self.push_grid_plan_to_db([res]) == 'true': res_str = "" res_str += "Загрузка произошла успешно \n" res_str += "Имя площадки {} \n".format(self.block_name) res_str += "Номер площадки {} \n".format(self.block_code) res_str += "Имя строенния {} \n".format(self.building_name) res_str += "Загружены следующие оси: " + ", ".join( [i["globalName"] for i in res["gridsData"]["Grids"]]) + "\n" res_str += "Загружены следующие уровни: \n" + "\n\t".join([ "{} ({})".format(i["name"], i["elevation"]) for i in res["gridsData"]["Levels"] ]) echo(res_str)
def calculate_mass(self): """ Подсчет массы. Считается по формулам описанным https://docs.google.com/spreadsheets/d/1qB8FUkEdyUgw6qt5sLppX-QyvMNmKUa-83KUxZC5I0E/edit?usp=sharing В случае ошибки выводит сообщение """ calc_type = self[par_names["Подсчет"]] mass = 0 try: if calc_type: calc_type = calc_type % 100 if calc_type == 1: mass = self["Количество"] * \ self["МассаПМ"] elif calc_type == 2: mass = self["Количество"] * \ self["МассаПМ"] * \ self["Длина"] / 1000 elif calc_type == 3: mass = self["Количество"] * \ self["МассаПМ"] * \ self["Площадь"] / 1000**2 elif calc_type == 4: mass = self["Количество"] * \ self["МассаПМ"] * \ self["Объем"] / 100**3 elif calc_type == 5: mass = self["Количество"] * \ self["Масса"] elif calc_type == 6: mass = self["Количество"] elif calc_type == 12: mass = self["МатериалОбъем"] / 1000**3 * \ self["МатериалПлотность"] except: echo("Ошибка в подсчете массы, {}".format(self)) return mass
def __init__(self, element, doc=None, panel=None, analys_geometry=False, develop=False): "Инициализация окна." super(Precast_window, self).__init__(element, doc, analys_geometry=analys_geometry, parent=panel) self.develop = develop self.element = element self.parent = panel # Сюда нужно будет потом записать Id который вернулся с сервера self.server_id = 0 # Это непонятно зачем. Нужно переделать get_parameter self.el_type = self.element.Symbol self.error_message = "" if self.parent: self.parent.add_child(self) if self.is_valid: if self.analys_geometry and self.parent.is_analysed: if self.json: json_par = self.prepare_json(self.json) # echo(json_par) if self.develop: self.element.LookupParameter("JSON").Set(json_par) result = self.UrlOpen(self.URI, parameters=json_par) if "exception" in result.keys(): echo("{} exception с сервера \"{}\"".format( self, result["exception"]["Message"])) pass elif "errors" in result.keys(): echo("{} errors с сервера \"{}\"".format( self, result["errors"])) else: self.server_window_obj = result self.server_id = result["id"] else: echo(self.error_message)
def get_button_or_create(self): """Существует ли кнопка. Если да - вернем ее.""" echo("Существует ли кнопка " + self.name) self.button = self.pushbutton_is_exist() if not self.button: echo("Нет") self.button = self.parent.sys_panel.AddItem(self.create_PPBD()) else: echo("Да")
def is_valid(self): if not hasattr(self, "_is_valid"): for i in self.children: if not i.is_valid: self._is_valid = False break else: point = self.make_real_point() x1 = round(point.X * 304.8, 5) x2 = round((self.parent.length * 304.8 - 15) - x1 - self.width * 304.8, 5) res1 = round( (x1 + self.modul_seam_width), 1) % self.modul_tiles_width res2 = round( (x2 + self.modul_seam_width), 1) % self.modul_tiles_width if not (res1 == 0 or res2 == 0): msg = "Не верное размещение окна по ширине. {}".format( self) echo(msg) self.element_error = msg self._is_valid = False else: self._is_valid = True return self._is_valid
def __init__(self, el, is_echo=False): "Создание экземпляр элемента параметризации." self.is_echo = is_echo self.element = el if isinstance(el, Rebar) or isinstance(el, RebarInSystem): pass else: pass par_code = self[self.parameter_code] if par_code: all_str = self.find_str_to_parse(self[self.parameter_code]) for i in all_str: prev_val = "'{{" + i + "}}'" new_val = self.calculate_symbol(i) new_val = new_val if isinstance(new_val, str) else str(new_val) par_code = par_code.replace(prev_val, new_val) par_code = par_code.replace("'", '"') try: if self.is_echo: echo(json.loads(par_code)) except: if self.is_echo: echo("Ошибка формирования json {}".format(self)) self["BDS_ReinforcementSymbol"] = par_code
def panel_is_exist(self): """Проверяет наличие панели в данной вкладке.""" echo("Панель " + self.name + " уже есть во вкладке " + self.parent.name + " ?") print(self.parent.name) for panel in __revit__.GetRibbonPanels(self.parent.name): if panel.Name == self.name: echo("да") return panel echo("нет") return False
def __init__(self, direct, script_path, is_user=False): """Инициализируем наш объект. Передать direct, is_user.""" self.is_user = is_user self.panels = [] self.sys_tab = None self.path = os.path.join(script_path, direct) echo("Создаем вкладку " + self.name) self.tab_is_create = False try: if not self.tab_is_exist(): self.sys_tab = self.create_tab() except Exception: echo("Ошибка при создании вкладки " + self.name) echo("Ищем панели в " + self.name) self.find_panel()
def create(cls, rvt_links, start_point): for rvt_link in rvt_links: rvt_link_doc = rvt_link.GetLinkDocument() if rvt_link_doc: title = rvt_link_doc.Title if title not in cls.rvt_links.keys(): cls.rvt_links[title] = cls(rvt_link_doc, start_point) level = rvt_link.LookupParameter(cls.level_parameter) section = rvt_link.LookupParameter(cls.section_parameter) if level and section: level = "%d" % level.AsDouble() section = section.AsString() if not level: echo("У связи {} не задан параметр {}".format( title, cls.level_parameter)) elif not section: echo("У связи {} не задан параметр {}".format( title, cls.section_parameter)) else: cls.rvt_links[title].add_level_to_section( section, level, rvt_link.GetTransform()) else: echo("Для связи {} не добавлен параметр {} либо {}".format( title, cls.level_parameter, cls.section_parameter))