from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application
rvt_year = int(app.VersionNumber)
def get_titleblocks_from_sheet(sheet, doc):
"""Function to get TitleBlocks from the given ViewSheet.
:param sheet: ViewSheet that has TitleBlock
:param doc: Document instance of the Project
:return: list of TitleBlocks that are placed on the given Sheet."""
rule_value = sheet.SheetNumber
param_sheet_number = ElementId(BuiltInParameter.SHEET_NUMBER)
f_pvp = ParameterValueProvider(param_sheet_number)
evaluator = FilterStringEquals()
if rvt_year < 2022:
f_rule = FilterStringRule(f_pvp, evaluator, rule_value, True)
else:
f_rule = FilterStringRule(f_pvp, evaluator, rule_value)
tb_filter = ElementParameterFilter(f_rule)
tb = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TitleBlocks) \
.WhereElementIsNotElementType().WherePasses(tb_filter).ToElements()
return list(tb)
if __name__ == '__main__':
random_sheet = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets)\
.WhereElementIsNotElementType().FirstElement()
title_block = get_titleblocks_from_sheet(random_sheet, doc)
__author__ = '🙋♂️ Erik Frits'