Matt asked this morning at RTC how to get a list of the users who own elements in a workshared file. Here’s a bit of code to do that.
public void UsersWhoOwnElements()
{
Document doc = this.ActiveUIDocument.Document;
IList<string> users = new List<string>();
// create an Or filter that takes ElementIsElementTypeFilter & the inverted version of ElementIsElementTypeFilter
// the result is that the filter returns every element in the model
foreach (Element e in new FilteredElementCollector(doc)
.WherePasses(new LogicalOrFilter
(new ElementIsElementTypeFilter(true),
new ElementIsElementTypeFilter(false))))
{
string owner = String.Empty;
CheckoutStatus cs = WorksharingUtils.GetCheckoutStatus(doc, e.Id, out owner);
if (owner != String.Empty && !users.Contains(owner))
users.Add(owner);
}
string info = String.Empty;
foreach (string s in users)
{
info += s + "\n";
}
TaskDialog.Show("Users = " + users.Count,"Users who own elements:\n" + info);
}
Hello Harry,
First of all thank you for the effort that you put on your Blog.
I would like to ask you if you can point me in the right direction for filtering elements by workset.
Basically what I want is to isolate in a view all the elements with one workset. The user would pick and object and the macro would isolate all the elements in the view with the same workset. I could try to iterate all the elements in the view and filter with an “if” statement. But I guess that wouldn’t be a good practice.
I have been looking ElementParameterFilter but I find it quite confusing.
What would be the best approach?
Kind regards,
Hernan
Hi Hernan
Thanks for your kind words. Does this old post help?
https://boostyourbim.wordpress.com/2015/07/24/rtcna-wish-7-granted-isolated-3d-view-for-each-workset/
Harry
Great! thanks! What I was looking for is “ElementWorksetFilter”, for some reason in couldn´t find it in the API docs or in the developer guide.