Who are the users with elements editable?

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.

users
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);
}
Advertisement