LearnRevitAPI
🤔How To Select Elements in Revit Last Changed By Specific User
Dec 16, 2024
Select Elements By User
🤔 Ever caught yourself asking, “Who did this?” in a Revit project? If yes, you’re not alone.
While there is a tool to identify who modified a specific element, it’s not much help when you want to select everything one user has touched.
💡 Let’s learn how to find, sort, and select elements last modified by a specific user.
Get All Elements
➡️ First, let’s get all 3D elements in our Revit project. We’ll use the FilteredElementCollector for that
. We can apply WhereElementIsViewIndependent to get all 3D Elements and exclude view dependant elements like tags and dimensions.
💡 Tip: You can adapt this method to collect different types of elements depending on your needs.
Who Did That?
Now we can go through all elements and look inside who has last touched them.
There is a WorksharingUtils class in Revit API that has a method - GetWorksharingTooltipInfo.
This method returns a WorksharingTooltipInfo object with these key properties:
Here is a code sample:
💡 Focus on the property that matters most to you.
Sort Elements by User
By now you have all 3D elements and you know who touched them last. Let's sort it in a dictionary sorted by LastChangedBy user.
I will use defaultdict. It allows you to specify the default value for items in case they don't exist. This will help you avoid the error and save a few lines of code so you can append items even to new keys right away.
❌ Otherwise you would need to check if user already exists in a dict, and either create an empty list or append to existing. Sounds boring, isn't it...
Here is the Code
👉 Select User from List
Lastly, let's create a simple UI form to choose between users to select elements.
The easiest way to do that is to use SelectFromList form from pyrevit.forms.
And that's how it will look:
Select Elements
Now we have everything we needed. We just need to select these elements with Selection.SetElementIds().
Since it need ICollection<ElementId> we need t convert a list of items into a .NET List[ElementIds]. That's not complicated, you just need to import it and specify the right Type.
Here is the code:
Final Code
✨ Here is the final Result put together.
Testimonial Highlight
🥳Another Happy LearnRevitAPI member
Learn more about LearnRevitAPI Here
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7500+ people!