How do I get all the worksets in the model without the need for a package? Better yet how can I get a workset by name?
The ‘Clockwork’ package has a Document.Worksets node that can get all worksets in the project but i cant remember if it gets names or ID
Try it anyway and unpack the python from it then you cnan make modifications to it if it gets the ID where you want the name.
Perhaps this is useful?
Cheers,
Mark
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
name_Input = IN[0]
userWorkset_List = Autodesk.Revit.DB.FilteredWorksetCollector(doc).OfKind(Autodesk.Revit.DB.WorksetKind.UserWorkset)
for userWorkset in userWorkset_List:
if userWorkset.Name == name_Input:
OUT = [userWorkset.Name, userWorkset]
Works perfectly! Thanks @Mark.Ackerley
Yes it looks like I do need the id instead of just a string to use this node…
What I am trying to do it pull a specific workset from the project and set all elements of a category on that workset. So grids would go on the shared grids and levels workset, and the reference planes and scope boxes would go on a specified workset from the project. Since the workset is built-in my project template, then I can specify it by name. I then use a custom pyRevit extension to push a button and resolve the elements on the wrong workset.
Hey,
Worksets, as you noticed need an id, you can just feed a number (double) in Dynamo and it will sort that out for you.
Hope that is useful,
Mark
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
name_Input = IN[0]
workset_List = Autodesk.Revit.DB.FilteredWorksetCollector(doc).OfKind(Autodesk.Revit.DB.WorksetKind.UserWorkset)
for workset in workset_List:
if workset.Name == name_Input:
OUT = float(str(workset.Id)), workset.Name, workset
Works perfectly! Thanks again @Mark.Ackerley. This is really helping me understand Revit API and python more.
Looks like there is a copy/paste error in the last line.