Transaction failure "Deleting all Open views in a project is not allowed"

Hi everyone,

I’m a newbie programmer guy, and I’m encountering an issue with my code. When attempting to delete worksets within a project, I’m encountering Revit error messages “Deleting all Open views in a project is not allowed”. I would greatly appreciate any assistance or guidance on how to resolve this.

Thank you in advance for your help!

for workset in current_worksets:
try:
WorksetID=workset.Id
WorksetTable.DeleteWorkset(doc,WorksetID,DeleteWorksetSettings())
workset_ids.append(workset.Id)
except ArgumentException:
pass

Please checkout the workset before executing this method. The method may fail in some situations that mentioned in CanDeleteWorkset(Document, WorksetId, DeleteWorksetSettings) . Another failure case is the Transaction failure due to “Deleting all open views in a project is not allowed.”

You need to checkout the worksets first

Hi Jean-Marc.

Thanks for your response.

I noticed that remark in the Revit API documentation, and I’ve already checked my worksets, for which I am the owner. The issue here seems to be the “Transaction failure.” Do you know how to solve it?

Thanks in advance

I’d try to remove the try except and print the workset name and parameters before trying to delete it to figure things out.