I am trying to collect all Worksets from a series of files at a directory.
I have found some Python script which I thought I might be able to modify, to collect the worksets and collate these in a list. Unfortunately I don’t have much experience with Python so am really guessing at the modifications. Could anyone make some suggestions to facilitate this?
For starters, you’ll need a for loop to iterate over your list of documents. At the moment, the script is set up for the FilteredWorksetCollector to work with one document. Here is how it can work to go through multiple documents:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
docs = IN[0]
worksets = []
for i in docs:
worksets.append(FilteredWorksetCollector(i).OfKind(WorksetKind.UserWorkset))
OUT = worksets, docs
I’m not sure what the portion of the script after the FilteredWorksetCollector is doing, is that your modification, and can you elaborate on what you’d like the script to do here?
I’ll be honest this was an amalgamation of a script to gather PBP values from multiple files, and a sample I found of another python script involving workset publication. I don’t have any experience with python and so was making a best guess.
Should I remove the FilteredWorksetCollector?
I understanding the docs in [0] to process the next doc in the directory. Is the for I in docs essential in this case?
Ah that makes sense - my last comment above about the last portion your script was because I was confused with the parts I saw in your Python script referring to Section name, etc., since it didn’t seem to be related to what your post was about.
You need the FilteredWorksetCollector to gather the worksets. The line “for i in docs” is a for loop, and is allowing the script to iterate over a list of documents, so yes it is essential for the script to collect worksets from multiple documents in the directory,
The Document.Worksets node (shown in your attached image above) is not needed if you are using the Python script to get an output of worksets (your list[0] in the codeblock) and their documents (your list[1] in the codeblock to use with Application.CloseDocument)
Thanks for the explanation! The script you shared does seem to collect the Worksets!
I seem to be only getting ‘Autodesk.Revit.DB.Workset’ as the Workset name though? Is there an addition I can make to the script to provide the workset name?