def categories_description(): for category_id in BuiltInCategory.GetValues(BuiltInCategory): try: category = Category.GetCategory(revit.doc, category_id) except: raise print(get_full_name(category))
def convertToCat( bicat ): with Transaction( doc, 'Convert Family' ) as t: t.Start() catobj = Category.GetCategory( doc, bicat ) doc.OwnerFamily.FamilyCategory = catobj doc.Regenerate() t.Commit()
def get_enhanced_ids(): # Modified category for Revit 2020 and above. When you change level, object doesn't move. eg. fittings. enhanced_cat = (BuiltInCategory.OST_DuctAccessory, BuiltInCategory.OST_DuctFitting, BuiltInCategory.OST_PipeAccessory, BuiltInCategory.OST_PipeFitting, BuiltInCategory.OST_CableTrayFitting, BuiltInCategory.OST_ConduitFitting) return (Category.GetCategory(doc, cat).Id for cat in enhanced_cat)
def get_terminals_in_selection(): terminals = [] terminal_cat_id = Category.GetCategory(doc, BuiltInCategory.OST_DuctTerminal).Id for id in uidoc.Selection.GetElementIds(): element = doc.GetElement(id) if element.Category.Id == terminal_cat_id: terminals.append(element) return terminals
def __init__(self, built_in_category): if isinstance(built_in_category, Category): self.built_in_category = [built_in_category.Id] else: if isinstance(built_in_category, BuiltInCategory): built_in_category = [built_in_category] self.built_in_category = [ Category.GetCategory(self.doc, i).Id for i in built_in_category ]
def get_color_from_colorscheme(view): cat = Category.GetCategory(doc, BuiltInCategory.OST_Rooms) color_scheme_id = view.GetColorFillSchemeId(cat.Id) # Получение цветовой схемы colorfill_scheme = doc.GetElement(color_scheme_id) if colorfill_scheme: entries = colorfill_scheme.GetEntries() # Получение всех элементов цветовой схемы data = {} for entry in entries: data[entry.GetStringValue()] = entry.Color return data
def create_views(value_provider, built_in_category_list, prefix, num_range, num_format): # type: (ParameterValueProvider, iter, str, iter, str) -> None # evaluator # rule_evaluator = FilterStringBeginsWith() rule_evaluator = FilterStringContains() # caseSensitive case_sensitive = True # categories cat_ids = List[ElementId]() for cat in built_in_category_list: cat_id = Category.GetCategory(doc, eval( "BuiltInCategory.{}".format(cat))).Id cat_ids.Add(cat_id) base_view = get_base_view("3DControlBaseView") with rpw.db.Transaction("Create 3D Control Views"): for n in num_range: # ruleString filter_string = "{prefix}{number:{num_format}}".format( prefix=prefix, number=n, num_format=num_format) # rules filter_string_rule = FilterStringRule(value_provider, rule_evaluator, filter_string, case_sensitive) inverse_filter_rule = FilterInverseRule(filter_string_rule) rules = List[FilterRule]() rules.Add(inverse_filter_rule) # Create Filter filter_element = ParameterFilterElement.Create( doc, "SAUF_{}".format(filter_string), cat_ids, rules) # Add filter to view view = doc.GetElement( base_view.Duplicate(ViewDuplicateOption.Duplicate)) view.Name = filter_string view.AddFilter(filter_element.Id) view.SetFilterVisibility(filter_element.Id, False)
def get_parameter_bindings(self): try: prj_defs = set() binding_map = self.doc.ParameterBindings it = binding_map.ForwardIterator() it.Reset() while it.MoveNext(): current_binding = it.Current if current_binding.Categories.Contains( Category.GetCategory(self.doc, BuiltInCategory.OST_MEPSpaces)): prj_defs.add(it.Key.Name) return prj_defs except Exception as e: logger.error(e, exc_info=True) pass
def join_elements(self, elements_1, elements_2): "Присоединяет геометрию элементов" result = set() rebar_cat = Category.GetCategory(self.doc, BuiltInCategory.OST_Rebar).Name elements_1 = [ i for i in elements_1 if i.element.Category.Name != rebar_cat ] elements_2 = [ i for i in elements_2 if i.element.Category.Name != rebar_cat ] for element_1 in elements_1: for element_2 in elements_2: try: res = BooleanOperationsUtils.ExecuteBooleanOperation( element_2.union_solid, element_1.union_solid, BooleanOperationsType.Difference) if res.Volume < element_2.union_solid.Volume: result.add(element_1) try: if not JoinGeometryUtils.AreElementsJoined( self.doc, element_2.element, element_1.element): JoinGeometryUtils.JoinGeometry( self.doc, element_2.element, element_1.element) if not JoinGeometryUtils.IsCuttingElementInJoin( self.doc, element_2.element, element_1.element): JoinGeometryUtils.SwitchJoinOrder( self.doc, element_2.element, element_1.element) except: # echo("Ошибка в объединении {} с {}".format(element_1, element_2)) pass except InvalidOperationException: result.add(element_1) return result
def create_baseplate_schedule(self): platemation_schedule = self.has_pmschedule() if not platemation_schedule: category = Category.GetCategory( doc, BuiltInCategory.OST_StructuralColumns) with revit.Transaction("Create Views"): # Create ViewSchedule platemation_schedule = ViewSchedule.CreateSchedule( doc, category.Id, # Insert Baseplate Model CategoryId ) platemation_schedule.Name = "BasePlateSchedule_platemation" #Add Field to show in schedule platemation_schedule_fields = platemation_schedule.Definition.GetSchedulableFields( ) for el in platemation_schedule_fields: try: if el.GetName(doc) in field_name: platemation_schedule.Definition.AddField(el) except Exception as e: print(e) #Add Filter to show only baseplate """
def add_baseplate_param(self): cd = os.getcwd() temp_paramfile = os.path.join(cd, "../Lib/PM_SharedParameters.txt") scolumn_category = Category.GetCategory( doc, BuiltInCategory.OST_StructuralColumns) cat_set = __revit__.Application.Create.NewCategorySet() cat_set.Insert(scolumn_category) instancebiding = __revit__.Application.Create.NewInstanceBinding( cat_set) biding_map = doc.ParameterBindings param_file = uidoc.Application.Application.OpenSharedParameterFile() def_groups = param_file.Groups for def_group in def_groups: if 'column' in def_group.Name.lower(): column_def = def_group for param in column_def.Definitions: if 'baseplate-type' in param.Name.lower(): bp_type_param = param elif 'baseplate-width' in param.Name.lower(): bp_width_param = param elif 'baseplate-height' in param.Name.lower(): bp_height_param = param elif 'baseplate-thickness' in param.Name.lower(): bp_thickness_param = param param_list = [ bp_type_param, bp_width_param, bp_height_param, bp_thickness_param ] with revit.Transaction("Add Column Param"): for param in param_list: try: biding_map.Insert(param, instancebiding, BuiltInParameterGroup.PG_IDENTITY_DATA) except: print(param.Definition.Name)
def __init__(self, cat): if isinstance(cat, BuiltInCategory): self.cat_name = Category.GetCategory(doc, cat).Name else: self.cat_name = cat.Name
def convertToCat( family, bicat ): famdoc = doc.EditFamily( family ) catobj = Category.GetCategory( famdoc, bicat ) famdoc.OwnerFamily.FamilyCategory = catobj famdoc.LoadFamily( doc )
def get_category_ids(self, categories): return tuple(Category.GetCategory(doc, cat).Id for cat in categories)
from Autodesk.Revit.DB import GraphicsStyleType, BuiltInCategory, Category clr.AddReference("RevitServices") from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument def lineweight(fill, weight=IN[4], graphStyle=GraphicsStyleType.Projection): return fill.SetLineWeight(weight, graphStyle) view = doc.ActiveView scale = view.Scale floor_fill = Category.GetCategory(doc, BuiltInCategory.OST_FloorsSurfacePattern) wall_fill = Category.GetCategory(doc, BuiltInCategory.OST_WallsSurfacePattern) ceilling_fill = Category.GetCategory( doc, BuiltInCategory.OST_CeilingsSurfacePattern) TransactionManager.Instance.EnsureInTransaction(doc) if IN[1]: lineweight(floor_fill) elif IN[2]: lineweight(wall_fill) elif IN[3]: lineweight(ceilling_fill) view.Scale = 1 view.Scale = scale
import clr clr.AddReference("RevitAPI") from Autodesk.Revit.DB import ColorFillScheme, FilteredElementCollector, ElementClassFilter, ElementId, View, \ BuiltInCategory, Category clr.AddReference("RevitServices") from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument view = doc.ActiveView class_filter = ElementClassFilter(ColorFillScheme) color_fill_scheme = view.GetColorFillSchemeId(ElementId(99859)) col = FilteredElementCollector(doc).OfClass(ColorFillScheme).ToElements() cat = Category.GetCategory(doc, BuiltInCategory.OST_Rooms) color_scheme_id = view.GetColorFillSchemeId(cat.Id) elem = doc.GetElement(color_scheme_id) # OUT = [doc.GetElement(c) for c in color_fill_scheme] OUT = elem