Rename an existing Workset

Is there a way to rename an existing workset to a different name in dynamo? I’m wanting to rename the default “Shared Levels and Grids” workset to a different name within a graph I have created that creates worksets based on our company standards. Thanks for any help in advance.

1 Like

I couldn’t find a custom node for renaming worksets, but it’s possible since 2015 R2 with the WorksetTable.RenameWorkset method.

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

#Converting input from Dynamo to Revit

workset = UnwrapElement(IN[0])
name = IN[1]


#rename workset in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

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

TransactionManager.Instance.TransactionTaskDone()

OUT = workset
4 Likes

Thanks. I knew it was in the API but I didn’t know enough about ironpython to implement it. Much appreciated.

Does this script accept lists if for example I want to batch rename worksets?

Or at least the 2 default ones?

Thanks…

Hi @Stavros_Koulis

Yes you can batch rename worksets. Read this how to handle list in Python Dividing parts with dynamo

I need this to run in batch but i cannot understand what Kulkul said here :

ive taken the liberty of with my basic python skills to update the python to work in revit 19 as the workset.id does not seem to be working
you will need to pass in another input as in[2] for workset.ids using something like a genius loci package
see attached graph

im feeding one workset at a time, but you can maybe use a different setup

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

#Converting input from Dynamo to Revit

workset = UnwrapElement(IN[0])
name = IN[1]
worksetID = UnwrapElement(IN[2])

#rename workset in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
WorksetTable.RenameWorkset(doc,worksetID,name);
TransactionManager.Instance.TransactionTaskDone()

OUT = workset