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);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s