I need to create a script that deletes all worksets from a model, while keeping the elements (all elements should be moved to “Workset1” and then remove all worksets
the logic is this (similar to revit workflow),
1- Set all elements workset parameter to “Workset1” (takes so much time on dynamo compared to revit)
2- then delete all worksets
I have managed to do the first one, but the second one i couldn’t do, no matter what package I use, I couldn’t get the elements ID to use element.delete
is there a way to do that? and is there a faster/better way to get the same result?
Was looking into similar for a customer a few eeeks back. If I recall the Revit API call to delete a workset can be found in the WorksetTable class, and is only available in 2023 and up. Using it requires creating an option class to either move elements to a specified workset id, or to delete them entirely.
I haven’t seen any nodes for this, but you can likely give it a shot in a Python node. Well unless you are in 2022 or an earlier version, in which case you will need to look for another option.
Not sure if we really want to revisit this but incase anyone cares heres a really terrible implementation.
The jyst is get worksets you want to delete. Get workset you want to move deleted workset items to. Delete the worksets. Worth noting I believe you need to have all the worksets checked out.
import clr
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import * #this is necessary
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
list=ListWorksetId
ws_Table=doc.GetWorksetTable()
all_WS = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)
for ws in all_WS:
if(ws.Name==“Workset 1”):
i=0#do nothing
else:
list.Add(ws.Id)
wkst1id=ws.Id
DWS=DeleteWorksetSettings(DeleteWorksetOption.MoveElementsToWorkset, wkst1id) #WorksharingUtils.CheckoutWorksets(doc,list) #could use this to checkout worksets
TransactionManager.Instance.EnsureInTransaction(doc)
for ws in all_WS:
if(“SYM” in ws.Name):
if(WorksetTable.CanDeleteWorkset(doc,ws.Id,DWS)):
WorksetTable.DeleteWorkset(doc,ws.Id,DWS)
TransactionManager.Instance.TransactionTaskDone()
OUT =
import clr
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import * # this is necessary
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
list=ListWorksetId()
ws_Table=doc.GetWorksetTable()
all_WS = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)
for ws in all_WS:
if(ws.Name==“Workset 1”):
i = 0 #do nothing
else:
list.Add(ws.Id)
wkst1id=ws.Id
DWS=DeleteWorksetSettings(DeleteWorksetOption.MoveElementsToWorkset, wkst1id)
# 🔓🔒 WorksharingUtils.CheckoutWorksets(doc,list) #could use this to checkout worksets
TransactionManager.Instance.EnsureInTransaction(doc)
for ws in all_WS:
if(“SYM” in ws.Name):
if(WorksetTable.CanDeleteWorkset(doc,ws.Id,DWS)):
WorksetTable.DeleteWorkset(doc,ws.Id,DWS)
TransactionManager.Instance.TransactionTaskDone()
OUT = "Done"
just pasted your code i think it needs still some maintance
can you work arrowned only with detach model and reopen without workset. there is a option after using e-transmit.