How to rename Worksets?

Hi - I am trying to batch rename Worksets. Admittedly I don’t have much experience with python and am really guessing at the modifications required to rename in batch vs. by single workset.

"
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])
names = IN[1]

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

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

TransactionManager.Instance.TransactionTaskDone()

OUT = worksets
";

Complete script;

ReName Worksets.dyn (14.4 KB)

Thanks for any help!!

You have to iterate over your lists of worksets and names using a ForLoop and zip()

import clr

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
uidoc = DocumentManager.Instance.CurrentUIDocument

worksets = UnwrapElement(IN[0])
names = IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)

for workset, name in zip(worksets,names):
	WorksetTable.RenameWorkset(doc,workset.Id, name)

OUT = worksets

Let me know if this works

2 Likes

Hi @awilliams - thank you for your help!!

I get;
IronPythonEvaluator.EvaluateIronPythonScript operation failed.
unexpected token ‘‘’

Hmm I don’t see any extraneous apostrophes in the code I pasted so I’m thinking maybe just a copy/paste error? Try deleting all the contents of your Python script node and repasting

This would pop up if you mixed tabs and spaces in the same file. I would just go through it and check that you are consistently using one or the other.

I ran the script above and it worked without error so it must be a copy/paste slip up, but thank you for that info! I read the error quickly and thought I saw “’” (an apostrophe). Good to know in case I run into that error on my end at some point

Ha, my bad. If it’s really just an apostrophe then you are totally right. It would not show that message. Any message about illegal characters or unexpected new line, could be caused by what I was referring to.

Could you show a screen shot of your graph and error?

Hi @awilliams, @Konrad_K_Sobon, @salvatoredragotta

I realized I was making a very beginner mistake :flushed: and importing the script as a string.

I am getting an error that the ‘GIven Workset Name is already in use’?

Thank you for your help!!

That’s pretty self explaining…given name is already used. Workset names must be unique.

1 Like

I tyring to rename this worksets to uppercase but it appears that the code have an error the python show Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 21, in
TypeError: expected WorksetId, got inttest.dyn (22.7 KB)

Same issue. checked in Cpython3 and same error:
No method matches given arguments for RenameWorkset: (<class ‘Autodesk.Revit.DB.Document’>, <class ‘int’>, <class ‘str’>)
seems workset.Id gives back an int and not the WorksetId element(that RenameWorkset wants).

Hello
a workaround


import clr

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
uidoc = DocumentManager.Instance.CurrentUIDocument

worksets = UnwrapElement(IN[0])
names = IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)

for workset, name in zip(worksets,names):
	if isinstance(workset.Id, int):
		WorksetTable.RenameWorkset(doc,WorksetId(workset.Id), name)
	else:
		WorksetTable.RenameWorkset(doc,workset.Id, name)

TransactionManager.Instance.TransactionTaskDone()

OUT = worksets

Many thanks!


Hi all, I seem to be having different issue here. The script runs with no warning but it only takes the first character of the intended Workset name. Anyone have a clue what could be causing this ??

@MReza

put the input name into a list with brackets [ ] (in the Code Block node)

1 Like