Worksets

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.

1 Like

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.

https://www.revitapidocs.com/2015/8a6f0949-069b-4b83-380c-f6582ef37a40.htm

https://www.revitapidocs.com/2015/cc477191-cc03-6dbf-48b7-fd08f83d75b6.htm

#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!