Check which user owns an element in a shared model

When working with the Revit API in shared models, we are unable to execute commands on elements that are owned by other users. The following code snippet shows how to handle this issue.

For the sake of arguement, let's imagine we want to perform an action on our walls.

doc = DocumentManager.Instance.CurrentDBDocument
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()
owned_walls = []
unowned_walls = []
for wall in walls:
wall_id = wall.Id
tooltipInfo = WorksharingUtils.GetWorksharingTooltipInfo(doc, wall_id)
owner = tooltipInfo.Owner
#If you're interested, you can also check who created the element and who edited it last.
creator = tooltipInfo.Creator
lastchangedby = tooltipInfo.LastChangedBy
if owner != "" and owner != "lorem.ipsum": #The element is owned (it doesn't belong to an empty string), and it's not owned by you (substitute your own username for "lorem.ipsum")
unowned_walls.append(wall)
else:
owned_walls.append(wall)
Once we've created the unowned_walls list, we can perform any function we want, safe in the knowledge that it's not owned by other users.

We can also choose to do something with the owned_walls list, like sending an email to the elements' owner, or appending them to a log to process later.

Comments

Popular posts from this blog

Create dimensions

Create Dimensions - Rooms