Hi guys, I found a dynamo script that allowed me to change the “editable” checkbox for worksets on revit. I re-created a dynamo script that creates all my necessary worksets and does a sync to the central model then unchecks the editable box however for some of the worksets I create I need to also uncheck the “visible in all views” box. Any ideas? Possibly a python script would do the trick!
Cheers
Can you post what you have tried so far? Ideally, this would include images and text (if applicable) of anything you have created.
Well here is what I have made. This script creates all the worksets I need and then syncs the project and unchecks the editable box.
Here is the python script I found on another forum;
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Import system library
clr.AddReference('System.Core')
from System.Collections.Generic import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
def ToList(x):
if isinstance(x,list):
return UnwrapElement(x)
else:
return [UnwrapElement(x)]
worksets = ToList(IN[0])
iDs = [ws.Id for ws in worksets]
Ids = List[WorksetId](iDs)
try: checkedout_ws = WorksharingUtils.CheckoutWorksets(doc,Ids)
except Exception,e: checkedout_ws = str(e)
OUT = checkedout_ws
I now need to make some of the worksets uncheck the “visible in all views box” im sure its possible with a similar python code I just dont have the knowledge to do so.
Cheers
Hi @angus
Yes it’s possible with python. There is a class called “WorksetDefaultVisibilitySettings” to set Default Workset Visibilty.
#import libraries
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# collect all worksets ids and names
filter = WorksetKindFilter(WorksetKind.UserWorkset)
WkSetId = [w.Id for w in FilteredWorksetCollector(doc).WherePasses(filter)]
WkSetNames = [w.Name for w in FilteredWorksetCollector(doc).WherePasses(filter)]
result = []
# Inputs
names,bool = IN
#Get WorksetDefaultVisibilitySettings and SetWorksetVisibilty by workset name
for wid, wnm in zip(WkSetId,WkSetNames):
if wnm in names:
TransactionManager.Instance.EnsureInTransaction(doc)
wvb=WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc).SetWorksetVisibility(wid,bool)
gwvb=WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc).IsWorksetVisible(wid)
if not gwvb:
result.append('Visibility in all Views Off')
else:
result.append('Visibility in all Views On')
TransactionManager.Instance.TransactionTaskDone()
OUT = result
Don’t forget to mark the post as solved.
Thats fantastic! Thank you very much for your help & the links to the revit api docs!
Hi @Kulkul,
I am attempting to modify your script to change Open/Closed worksets instead of the visibility on views. However, I have little or no knowledge of Python code. I have modified the code below, but nothing happens when I run the script.
#import libraries
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# collect all worksets ids and names
filter = WorksetKindFilter(WorksetKind.UserWorkset)
WkSetId = [w.Id for w in FilteredWorksetCollector(doc).WherePasses(filter)]
WkSetNames = [w.Name for w in FilteredWorksetCollector(doc).WherePasses(filter)]
result = []
#Open all worksets
TransactionManager.Instance.EnsureInTransaction(doc)
WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets).Open(WkSetId)
TransactionManager.Instance.TransactionTaskDone()
OUT = []