LearnRevitAPI

Sep 30, 2023

Select Elements Modifed By a User

🤔 Have you ever wondered, "Who did this or changed that in our work-sharing Revit project?" 

Well, pyRevit has a tool that can give us answers for one element. But what if we need to select everything that someone changed in our project?

💡 Let's learn how to select elements that were last modified by someone.

👀 Get All Elements

➡️ First of all let's get all 3D Elements in our Revit Project, so we can sort it by users. Obviously we will use FilteredElementCollector

I will also make sure that I am selecting Family Instances and they are View Independent .

💡 You can use different method to get your elements.

👽 Who Did That?

🔁 To sort elements by user we need to get that information from Elements. There is a class in Revit API WorksharingUtils

👉 Inside there is a method called GetWorksharingTooltipInfo.

This method will return you WorksharingTooltipInfo

And it has the following properties:

.Creator
.Owner

.LastChangedBy


💡 You can choose which property you are interested in.
👇 Here is an example

↪️ Sort Elements by User

💡 Now we know how to get elements and get information about users from them. Let's create a dictionary where we sort all elements by LastChangedBy users.  

📦 To do that, we will use defaultdict

✅ They allow us to specify default value for each of the items in a dict. And we want each user to start with an empty list, so we can append elements to it.

❌ Otherwise you would need to check if user already exists in a dict, and either create an empty list or append to existing. We don't want to do that.

👉 Select User from List

✅ We have a list of all elements sorted by users. Let's ask our end-user whose elements we want to select.

📃 For that we will use SelectFromList form from pyrevit.forms. It's very simple to use and pyRevit documentation has examples that you can copy-paste.

💡 Check out pyRevit Forms if you never heard of them yet!

🎯 Select Elements

Now we have everything we needed. We just need to select these elements.

Let's use Selection.SetElementIds()  

It takes 1 argument which has to be ICollection<ElementId> 

But we will use List[ElementId]

Here is the snippet that will prepare List[ElementId]
and change Revit UI Selection.
👇

🎯 Final Code

✨ Here is the final Result put together.

P.S.

Hey guys, I am sorry for being so inconsistent on my YouTube and Newsletter...

As you already know I am very close to launch my Learn Revit API Course,  but there is still so much work before I can release Early-Bird access.

I am already in the finish line, so I will do everything to release it this October. You will hear about it via my Newsletter for sure!

Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 6700+ people!