I am trying to develop a script that will batch rename worksets in a model. After searching this forum I have gotten a good start. However my Python coding skills are lacking and my script is generating warnings and not renaming the worksets. See code block and image below. Also attached is my Dynamo graph. I would greatly appreciate any guidance and help anyone is willing to provide. Thank You.
BatchRenameWorksets.dyn (5.7 KB)
.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
#Functions for list handling
def ProcessList(_func, _list):
return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )
def ProcessParallelLists(_func, *lists):
return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )
#Preparing input from dynamo to revit
def Unwrap(item):
return UnwrapElement(item)
def ToRevit(item):
return item.ToRevitType(True)
if isinstance(IN[0], list):
workset = ProcessList(Unwrap, IN[0])
else:
workset = list(Unwrap(IN[0]))
if isinstance(IN[1], list):
name = ProcessList(Unwrap, IN[1])
else:
name = list(Unwrap(IN[1]))
#rename workset in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
WorksetTable.RenameWorkset(doc,workset.Id,name);
TransactionManager.Instance.TransactionTaskDone()
OUT = workset