Very simple and compact graph for Finding and Replacing override values in ALL dimensions in the project.
NOTE this has been formatted to work with CPython3 not IronPython2
#Sean Page, 2021
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
results = []
StrFind = IN[0]
StrReplace = IN[1]
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#Get all dimensions in the entire project
dims = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Dimensions).WhereElementIsNotElementType().ToElements()
#Loop every dimension
for dim in dims:
#This first group will check for values when the dimension is singular or doesn't have multiple segments
temp = []
#Check each of the Override options for the search value (Above, Below, Prefix, Suffix,ValueOverride)
if dim.Below and StrFind in dim.Below:
temp.append(dim)
#Replace with the search criteria (typical)
dim.Below = dim.Below.replace(StrFind,StrReplace)
if dim.Above and StrFind in dim.Above:
temp.append(dim)
dim.Above = dim.Above.replace(StrFind,StrReplace)
if dim.ValueOverride and StrFind in dim.ValueOverride:
temp.append(dim)
dim.ValueOverride = dim.ValueOverride.replace(StrFind,StrReplace)
if dim.Prefix and StrFind in dim.Prefix:
temp.append(dim)
dim.Prefix = dim.Prefix.replace(StrFind,StrReplace)
if dim.Suffix and StrFind in dim.Suffix:
temp.append(dim)
dim.Suffix = dim.Suffix.replace(StrFind,StrReplace)
if temp:
results.append(temp)
continue
#Now we need to check each segment for multi segment dimensions
for seg in dim.Segments:
#Check each of the Override options for the search value (Above, Below, Prefix, Suffix,ValueOverride)
if seg.ValueOverride and StrFind in seg.ValueOverride:
temp.append(seg)
#Replace with the search criteria (typical)
seg.ValueOverride = seg.ValueOverride.replace(StrFind,StrReplace)
if seg.Above and StrFind in seg.Above:
temp.append(seg)
seg.Above = seg.Above.replace(StrFind,StrReplace)
if seg.Below and StrFind in seg.Below:
temp.append(seg)
seg.Below = seg.Below.replace(StrFind,StrReplace)
if seg.Prefix and StrFind in seg.Prefix:
temp.append(seg)
seg.Prefix = seg.Prefix.replace(StrFind,StrReplace)
if seg.Suffix and StrFind in seg.Suffix:
seg.Suffix = seg.Suffix.replace(StrFind,StrReplace)
#Check to see if any values were changed with the temp list
if temp:
#If the values were changed, append the list of temp elements
results.append(temp)
TransactionManager.Instance.TransactionTaskDone()
OUT = results