Workset Name Publish to List - From Directory

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?

Help!

1 Like

What happens when you use the regular python node (not scripting)?

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?

2 Likes

Hi awilliams,

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?

Thanks for your help,
Jaclyn

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)

The script I attached above should work. :slight_smile:

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?

Thanks for your help!

change to the following lines of code:

for doc in docs:
	worksets.append([workset.Name for workset in FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)])
3 Likes

Glad I could help @jaclyn.s and oops - I hadn’t tested it and blanked on including the name. Thanks @salvatoredragotta :blush:

1 Like

Thanks awilliams & salvatoredragotta!

The revision provided works - for record the complete version is below.


"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 doc in docs:
worksets.append([workset.Name for workset in FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)])

OUT = worksets, docs;

";


That’s good but you should mark someone else as solution :grin:

1 Like

@salvatoredragotta it’s corrected now :wink:

Thanks @Kulkul & @salvatoredragotta for clarifying!!
(I am new to the forums and so will keep this in mind for future posts)