Hi, is it possible to make a workset editable? I am trying to delete a workset, and the delete worksets node from Genius Loci is what I need, but it cannot delete noneditable worksets…
Hi @ChrisGamble
try this version
#Alban de Chasteigner 2021
#twitter : @geniusloci_bim
#geniusloci.bim@gmail.com
#https://github.com/albandechasteigner/GeniusLociForDynamo
# updated by Cyril Poupin 08/12/2024
import clr
import sys
import System
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
deleteIds = IN[0] if isinstance(IN[0],list) else [IN[0]]
option = IN[1]
destinationIds = IN[2] if isinstance(IN[2],list) else [IN[2]]
names = []
# ensure convert to List<WorksetId>
destinationIds = List[WorksetId]([x if isinstance(x, WorksetId) else WorksetId(x) for x in destinationIds])
deleteIds = List[WorksetId]([x if isinstance(x, WorksetId) else WorksetId(x) for x in deleteIds])
TransactionManager.Instance.ForceCloseTransaction()
# set Worksets editables
destinationIds = WorksharingUtils.CheckoutWorksets(doc, destinationIds)
deleteIds = WorksharingUtils.CheckoutWorksets(doc, deleteIds)
TransactionManager.Instance.EnsureInTransaction(doc)
doc.Regenerate()
if option == "MoveElementsToWorkset" :
deleteWorksetSettings = DeleteWorksetSettings()
deleteWorksetSettings.DeleteWorksetOption = DeleteWorksetOption.MoveElementsToWorkset
deleteWorksetSettings.WorksetId = destinationIds[0]
else:
deleteWorksetSettings = DeleteWorksetSettings()
for worksetId in deleteIds :
if WorksetTable.CanDeleteWorkset(doc, worksetId, deleteWorksetSettings):
WorksetTable.DeleteWorkset(doc, worksetId, deleteWorksetSettings)
names.append(doc.GetWorksetTable().GetWorkset(worksetId).Name)
else:
names.append("The workset is not editable by the current user or is owned by other user")
TransactionManager.Instance.TransactionTaskDone()
if isinstance(IN[0], list): OUT = names
else: OUT = names[0]
1 Like
The CheckoutWorksets method also returns the Ids of all now and previously editable worksets provided to it I believe, which might simplify the logic of the process should you ever deal with lists of worksets to delete/move elements to. In the case of the above scenario you would also know that if the returned list has less than 2 objects, the process can not proceed.
2 Likes
fixed, thanks
1 Like