# Delete all Worksets without deleting any elements

**URL:** <https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521>\
**Category:** Uncategorized\
**Created:** [September 6, 2023, 6:48am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521 "2023-09-06T06:48:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![NERDASORUS](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NERDASORUS](https://forum.dynamobim.com/u/NERDASORUS)\
**Post date:** [September 6, 2023, 6:48am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/1 "2023-09-06T06:48:06Z")

</div>

Hello

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?

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 6, 2023, 6:49am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/2 "2023-09-06T06:49:42Z")

</div>

@NERDASORUS ,

you would lose the possibility of central model itself so i recomment you detach your modell and save it without Worksets! f.e. eTransmit

KR

Andreas

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 6, 2023, 7:08am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/3 "2023-09-06T07:08:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [September 6, 2023, 7:19am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/4 "2023-09-06T07:19:55Z")

</div>

Genius Loci have one “workset delete” but as mention only will work from 2022.1

---

<div class="post-metadata">

**Author:** ![NERDASORUS](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NERDASORUS](https://forum.dynamobim.com/u/NERDASORUS)\
**Post date:** [September 6, 2023, 8:30am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/5 "2023-09-06T08:30:59Z")

</div>

Appreciate the input guys, thank you.

---

<div class="post-metadata">

**Author:** ![VDCTrades3](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@VDCTrades3](https://forum.dynamobim.com/u/VDCTrades3)\
**Post date:** [October 11, 2024, 5:52pm UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/6 "2024-10-11T17:52:00Z")

</div>

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 =

---

<div class="post-metadata">

**Author:** ![VDCTrades3](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@VDCTrades3](https://forum.dynamobim.com/u/VDCTrades3)\
**Post date:** [October 11, 2024, 5:52pm UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/7 "2024-10-11T17:52:36Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/6/5643e98d91f9a5cb08fc5d7963f93db66b6090bc.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [December 18, 2024, 11:45am UTC](https://forum.dynamobim.com/t/delete-all-worksets-without-deleting-any-elements/93521/8 "2024-12-18T11:45:44Z")

</div>

@VDCTrades3

```py
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.
