Well done @AmolShah.
I’ll add a bonus - This add sets the ‘true false’ which was previously only serving the purpose of forcing a regen, so that it either locks or unlocks the dimension:
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
dims = UnwrapElement(IN[0])
lock = IN[1]
if not hasattr(dims,'__iter__'):
dims = [dims]
TransactionManager.Instance.EnsureInTransaction(doc)
for dim in dims:
if dim.NumberOfSegments>0:
for ds in dim.Segments:
ds.IsLocked = lock
else:
dim.IsLocked = lock
TransactionManager.Instance.TransactionTaskDone()
OUT = dims
Likely worth reducing the imports there if this is all you want to do - this feels a bit heavy handed.