I have been looking at the api but have not seem to come across a way to rename linestyles. I know it can be done with Ideate though. just thought i could try it with pyrevit.
Can this be done?
Any references would be greatly appreciated.
I have been looking at the api but have not seem to come across a way to rename linestyles. I know it can be done with Ideate though. just thought i could try it with pyrevit.
Can this be done?
Any references would be greatly appreciated.
I think the name comes from the GraphicsStyleCategory of the GraphicsStyle.
And I think its Name IsReadOnly
Builtin line styles cannot be renamed, but custom ones yes
untested, but it should look something like
import re
from pyrevit import revit, DB
def rename_linestyles(doc, find_text, replace_text, match_case):
lines_cat = doc.Settings.Categories.get_Item(DB.BuiltInCategory.OST_Lines)
with revit.Transaction("Rename Linestyle"):
for subcat in lines_cat.SubCategories:
if match_case:
if find_text in subcat.Name:
element = doc.GetElement(subcat.Id)
if element:
element.Name = subcat.Name.replace(find_text, replace_text)
else:
if find_text.upper() in subcat.Name.upper():
element = doc.GetElement(subcat.Id)
if element:
pattern = re.compile(re.escape(find_text), re.IGNORECASE)
element.Name = pattern.sub(replace_text, subcat.Name)
# then use the def
i shall give this a shot. so far i have not had luck
Jean-Marc is right. His code does work for this.
In fact it seems to work for any category you want to collect - you can rename its subcategories.
Super-useful.
Just tried it and it worked. Thanks @Jean-Marc ![]()