Help With Batch Renaming Worksets

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

I think you can use SetName node in clockwork for this.

@Luke_Johnson,

Thank you for the reply. Unfortunately it does not appear that the SetName node from clockwork will rename the worksets. Please see image.

Hi @jmmiller & @Luke_Johnson - were you able to solve this with python?
I had thought something like the below might work - but am also very new to python and am trying to piece this together;


"
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

docs = IN[0]

worksets = UnwrapElement(IN[1])
name = IN[2]

#rename workset in a transaction
for doc in docs:
worksets.append([Workset.Name for workset in FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)])

WorksetTable.RenameWorkset(docs,workset.Id,name);

TransactionManager.Instance.TransactionTaskDone()

OUT = docs, worksets;
";