Hello,
I am trying to generate a tool that iterates through the views of a project and for those that have a specific View Template prefix in the name, do something with the room tags.
My problem is that I am unable to obtain for a view, the view template name as a string in order to compare it to my list of prefixes.
Below my code, and the error.
Do I need any other method to obtain the name of the view template as a string?
import Autodesk.Revit.DB as DB
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
# Gel all floor plan views
all_floor_plan_views = DB.FilteredElementCollector(doc)\
.OfCategory(DB.BuiltInCategory.OST_Views)\
.WhereElementIsNotElementType().ToElements()
# Define the view template name prefixes to process
view_template_prefixes = ["BSE_03_PAP_"]
if __name__ == '__main__':
t = DB.Transaction(doc,__title__)
t.Start()
# Loop through all floor plan views
for view in all_floor_plan_views:
if view.ViewType == DB.ViewType.FloorPlan:
view_template_name = DB.Element.Name.__get__(doc.GetElement(view.ViewTemplateId))
# Check if the view template name starts with any of the specified prefixes
if any(view_template_name.startswith(prefix) for prefix in view_template_prefixes):
# Get all MEP Space Tags in the current view
space_tags = DB.FilteredElementCollector(doc, view.Id) \
.OfCategory(DB.BuiltInCategory.OST_MEPSpaceTags) \
.WhereElementIsNotElementType().ToElements()
# Loop through all MEP Space Tags
for tag in space_tags:
# Get the associated MEP Space element
space = doc.GetElement(tag.GetSpace())
# Position the tag at the same location as the space's reference point
tag.Location.Point = space.Location.Point
# Print a message for the processed view
print("Processed view: " + view.ViewName)
# Print a completion message
print("Script completed successfully.")
t.Commit()
But for the line
if any(view_template_name.startswith(prefix) for prefix in view_template_prefixes):
I receive the following error
line 86, in <module>
AttributeError: 'getset_descriptor' object has no attribute 'startswith'