Element Worksharing Information

This post is about collecting element’s worksharing information from a central model 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

And create output lists, you will notice that each list contains a value which is the title of each Excel column. And then append associate data to each of the list.

# create output properties values list
status, elementids, categories, ftypes, creators, owners, lastchangers = 
["Status"], ["ElementId"], ["Category"], ["FamilyType"],
["Creator"], ["Owner"], ["LastChangedBy"]
figure – 1.0 Output Data to Excel

Next step, loop through the input element(s) and collect the information. WorksharingUtils class contains utility methods for element’s worksharing data. Collect element’s information in the central model by using GetWorksharingTooltipInfo method with two arguments (element’s document & element’s Id).

# input elements
elems = UnwrapElement(IN[0])

for e in elems:
	# element's doc
	c_doc = e.Document
	# get worksharing info
	wsu = WorksharingUtils.GetWorksharingTooltipInfo(c_doc,e.Id)

GetWorksharingTooltipInfo method returns WorksharingTooltipInfo object which contains element’s Creator, LastChangedBy and Owner properties.

WorksharingTooltipInfo Properties

GetModelUpdatesStatus method returns ModelUpdatesStatus enumeration which indicates whether an element in the current model has additional user changes in the central model.

	# get element status in model
	status.append(WorksharingUtils.GetModelUpdatesStatus(c_doc,e.Id))
ModelUpdatesStatus Enumeration

Finally, collect element’s property/information : ElementId, Category, FamilyType, Creator, Owner, LastChangedBy and append to its associate output list.

	# append properties values
	# get element Id
	elementids.append(e.Id)
	# get category name
	categories.append(e.Category.Name)
	# get family type
	ftypes.append(c_doc.GetElement(e.GetTypeId()))
	# get element's creator
	creators.append(wsu.Creator)
	# get current owner 
	owners.append(wsu.Owner)
	# get last changer
	lastchangers.append(wsu.LastChangedBy)

# output lists
OUT = status, elementids,categories,ftypes, creators, owners, lastchangers

Sample usage, output result and the complete code is below.

Sample Usage
Output Result
# 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 properties values list
status,elementids,categories,ftypes, creators, owners, lastchangers =["Status"], ["ElementId"],["Category"],["FamilyType"],["Creator"],["Owner"],["LastChangedBy"] 

# input elements
elems = UnwrapElement(IN[0])

for e in elems:
	# element's doc
	c_doc = e.Document
	# get worksharing info
	wsu = WorksharingUtils.GetWorksharingTooltipInfo(c_doc,e.Id)
		
	# append properties values
	# get element status in model
	status.append(WorksharingUtils.GetModelUpdatesStatus(c_doc,e.Id))
	# get element Id
	elementids.append(e.Id)
	# get category name
	categories.append(e.Category.Name)
	# get family type
	ftypes.append(c_doc.GetElement(e.GetTypeId()))
	# get element's creator
	creators.append(wsu.Creator)
	# get current owner 
	owners.append(wsu.Owner)
	# get last changer
	lastchangers.append(wsu.LastChangedBy)

# output lists
OUT = status, elementids,categories,ftypes, creators, owners, lastchangers

Screenshots from https://www.revitapidocs.com/

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 )

Google photo

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

Twitter picture

You are commenting using your Twitter 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.