__welcome__ = """WELCOME!
You will find various code snippets you could easily copy/paste to use in your own sciprt.
Happy Coding!
- Erik Frits"""
from Autodesk.Revit.DB import *
import clr
clr.AddReference('System')
from System.Collections.Generic import List
app = __revit__.Application
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
all_rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToElements()
all_windows = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows).WhereElementIsNotElementType().ToElements()
all_doors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()
all_floors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().ToElements()
all_str_col = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).WhereElementIsNotElementType().ToElements()
all_generic = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().ToElements()
all_roofs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs).WhereElementIsNotElementType().ToElements()
all_window_types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows).WhereElementIsElementType().ToElements()
all_door_types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsElementType().ToElements()
all_floot_types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsElementType().ToElements()
all_walls = FilteredElementCollector(doc).OfClass(Wall).ToElements()
all_lines = FilteredElementCollector(doc).OfClass(CurveElement).ToElements()
materials = FilteredElementCollector(doc).OfClass(Material).ToElements()
all_wall_types = FilteredElementCollector(doc).OfClass(WallType).ToElements()
all_floor_types = FilteredElementCollector(doc).OfClass(Floor).ToElements()
all_ceil_types = FilteredElementCollector(doc).OfClass(CeilingType).ToElements()
all_worksets = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)
all_materials = FilteredElementCollector(doc).OfClass(Material).ToElements()
all_lines = FilteredElementCollector(doc).OfClass(CurveElement).ToElements()
all_detail_lines = [l for l in all_lines if l.CurveElementType == CurveElementType.DetailCurve]
all_model_lines = [l for l in all_lines if l.CurveElementType == CurveElementType.ModelCurve]
all_regions = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_FilledRegion).WhereElementIsNotElementType().ToElements()
all_region_types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_FilledRegion).WhereElementIsElementType().ToElements()
all_symbols = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
all_tags_walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_WallTags).WhereElementIsNotElementType().ToElements()
all_tags_windows = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_WindowTags).WhereElementIsNotElementType().ToElements()
all_imgs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RasterImages).WhereElementIsElementType().ToElements()
all_levels = FilteredElementCollector(doc).OfClass(Level).ToElements()
all_grids = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Grids).WhereElementIsNotElementType().ToElements()
all_text_notes = FilteredElementCollector(doc).OfClass(TextNote).ToElements()
all_spot_elev = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_SpotElevations).WhereElementIsNotElementType().ToElements()
all_sheets = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType().ToElements()
all_views = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
all_view_filters = FilteredElementCollector(doc).OfClass(FilterElement).ToElementIds()
all_drafting = [view for view in all_views if view.ViewType == ViewType.DraftingView]
all_ceil_views = [view for view in all_views if view.ViewType == ViewType.CeilingPlan]
all_floor_plans = [view for view in all_views if view.ViewType == ViewType.FloorPlan]
all_elevations = [view for view in all_views if view.ViewType == ViewType.Elevation]
all_area_views = [view for view in all_views if view.ViewType == ViewType.AreaPlan]
all_sections = [view for view in all_views if view.ViewType == ViewType.Section]
all_3D_views = [view for view in all_views if view.ViewType == ViewType.ThreeD]
all_details = [view for view in all_views if view.ViewType == ViewType.Detail]
all_legends = [view for view in all_views if view.ViewType == ViewType.Legend]
view_types = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
view_types_sections = [vt for vt in view_types if vt.ViewFamily == ViewFamily.Section]
view_types_legends = [vt for vt in view_types if vt.ViewFamily == ViewFamily.Legend]
selected_element_ids = uidoc.Selection.GetElementIds()
if selected_element_ids:
excl_collector = FilteredElementCollector(doc, active_view.Id)\
.Excluding(selected_element_ids)\
.WhereElementIsNotElementType()\
.ToElements()
print('There are {} Elements Excluding current selection in the Active View'.format(len(excl_collector)))
random_level = FilteredElementCollector(doc)\
.OfClass(Level)\
.FirstElement()
lvl_filter = ElementLevelFilter(random_level.Id)
rooms_on_lvl = FilteredElementCollector(doc)\
.OfCategory(BuiltInCategory.OST_Rooms)\
.WherePasses(lvl_filter)\
.ToElements()
walls_on_lvl = FilteredElementCollector(doc)\
.OfCategory(BuiltInCategory.OST_Walls)\
.WherePasses(lvl_filter)\
.ToElements()
print('There are {} Rooms on Level: {}'.format(len(rooms_on_lvl),
random_level.Name))
print('There are {} Walls on Level: {}'.format(len(walls_on_lvl),
random_level.Name))
from Autodesk.Revit.UI.Selection import ObjectType
ref = uidoc.Selection.PickObject(ObjectType.Element)
elem = doc.GetElement(ref)
if type(elem) != FilledRegion:
import sys
sys.exit()
region = elem
boundaries = region.GetBoundaries()
solid = GeometryCreationUtilities.CreateExtrusionGeometry(boundaries, XYZ(0, 0, 1), 1000)
filter = ElementIntersectsSolidFilter(solid)
inter_el_ids = FilteredElementCollector(doc) \
.WhereElementIsNotElementType() \
.WherePasses(filter) \
.ToElementIds()
uidoc.Selection.SetElementIds(inter_el_ids)
from Autodesk.Revit.DB.Structure import StructuralInstanceUsageFilter, StructuralInstanceUsage
filter_str_wall = StructuralInstanceUsageFilter(StructuralInstanceUsage.Wall)
filter_str_col = StructuralInstanceUsageFilter(StructuralInstanceUsage.Column)
filter_str_gir = StructuralInstanceUsageFilter(StructuralInstanceUsage.Girder)
elements = FilteredElementCollector(doc).WherePasses(filter_str_gir).ToElements()
count = len(elements)
print("Number of Elements in the document: {}".format(count))
base_pnt = XYZ(15, 15, 0)
filter = BoundingBoxContainsPointFilter(base_pnt)
collector = FilteredElementCollector(doc)
contain_elements = collector.WherePasses(filter).ToElements()
print('BB Contains Point Found:')
for i in contain_elements :
print(i)
not_contain_filter = BoundingBoxContainsPointFilter(base_pnt, True)
collector = FilteredElementCollector(doc)
not_contain_walls = collector.OfClass(Wall).WherePasses(not_contain_filter).ToElements()
print('Walls with BB Not Contains Found:')
for i in not_contain_walls:
print(i)
my_out_ln = Outline(XYZ(50, 0, 0), XYZ(80, 30, 10))
filter = BoundingBoxIntersectsFilter(my_out_ln)
collector = FilteredElementCollector(doc, doc.ActiveView.Id)
elements = collector.WherePasses(filter).ToElements()
for i in elements:
print(i)
invert_filter = BoundingBoxIntersectsFilter(my_out_ln, True)
collector = FilteredElementCollector(doc)
not_intersect_walls = collector.OfClass(Wall).WherePasses(invert_filter).ToElements()
cats = [
BuiltInCategory.OST_Walls,
BuiltInCategory.OST_Floors,
BuiltInCategory.OST_Roofs,
BuiltInCategory.OST_Ceilings
]
import clr
clr.AddReference('System')
from System.Collections.Generic import List
List_cats = List[BuiltInCategory](cats)
multi_cat_filter = ElementMulticategoryFilter(List_cats)
elements = FilteredElementCollector(doc).WherePasses(multi_cat_filter).ToElements()
import clr
clr.AddReference('System')
from System.Collections.Generic import List
from System import Type
types = [Wall, Floor, RoofBase, Ceiling]
List_types = List[Type]()
for i in types:
List_types.Add(i)
multi_class_filter = ElementMulticlassFilter(List_types)
elements = FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(multi_class_filter).ToElements()
for el in elements:
print(el)
worksets = FilteredWorksetCollector(doc) \
.OfKind(WorksetKind.UserWorkset)
for workset in worksets:
workset_filter = ElementWorksetFilter(workset.Id)
elements_in_workset = FilteredElementCollector(doc) \
.WherePasses(workset_filter) \
.ToElements()
print('Workset: {} has {} Elements'.format(workset.Name,
len(elements_in_workset)))
type_name = '2000 x 2250'
p_type_id = ElementId(BuiltInParameter.SYMBOL_NAME_PARAM)
f_param = ParameterValueProvider(p_type_id)
evaluator = FilterStringEquals()
value = type_name
rvt_year = int(app.VersionNumber)
if rvt_year >= 2023:
f_rule = FilterStringRule(f_param, evaluator, value)
else:
f_rule = FilterStringRule(f_param, evaluator, value, False)
filter_fam_name = ElementParameterFilter(f_rule)
elements = FilteredElementCollector(doc)\
.WherePasses(filter_fam_name)\
.WhereElementIsNotElementType()\
.ToElements()
el_ids = [el.Id for el in elements]
List_el_ids = List[ElementId](el_ids)
uidoc.Selection.SetElementIds(List_el_ids)