This post is about previewing the worksets information of the unopened Revit Document by using IronPython in Revit Dynamo Application.
First to import the modules: clr to load .Net Assemblies as IronPython modules : RevitAPI.dll for DB, RevitServices.dll for DocumentManager and TransactionManager. Collect the current document and store in doc variable.
# dynamo version - 1.3.4
import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
# the current document
doc = DocumentManager.Instance.CurrentDBDocument
Create output lists : names, ids, owners to append each workset’s name, id, and current owner of the workset. Next, the input IN[0] which is expecting a Revit file path and the path must be a string type. And convert this provided input File Path as a Model Path by using ConvertUserVisiblePathToModelPath method from ModelPathUtils class.
# output lists
names, ids, owners = [], [], []
# input filepath
file_path = IN[0]
# convert filepath to modelpath
model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(file_path)

WorksharingUtils class contains utility methods for element’s worksharing data. Collect workset’s information by using GetUserWorksetInfo method with one argument (model_path).

# collect worksets info
worksets = WorksharingUtils.GetUserWorksetInfo(model_path);

From collected worksets list, loop through each workset and get Name, Id, and Owner information of the workset. And append to associate output list.
# each workset
for workset in worksets:
# workset name
names.append(workset.Name)
# workset id
ids.append(workset.Id)
# workset owner
owners.append(workset.Owner)
# output results
OUT = names, ids, owners
Sample usage and complete code is below.

# dynamo version - 1.3.4
import clr
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
# the current document
doc = DocumentManager.Instance.CurrentDBDocument
# output lists
names, ids, owners = [], [], []
# input filepath
file_path = IN[0]
# convert filepath to modelpath
model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(file_path)
# collect workset info
worksets = WorksharingUtils.GetUserWorksetInfo(model_path);
# each workset
for workset in worksets:
# workset name
names.append(workset.Name)
# workset id
ids.append(workset.Id)
# workset owner
owners.append(workset.Owner)
# output results
OUT = names, ids, owners
Screenshot from https://www.revitapidocs.com/