Preview Workset Information

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 DBRevitServices.dll for DocumentManager and TransactionManagerCollect 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)
ConvertUserVisiblePathToModelPath method

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);
GetUserWorksetInfo method

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.

Sample Usage
# 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/

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.