#RTCNA wish 7 granted! Isolated 3d view for each workset

Create a 3d view for each workset, and in that view isolate the display of the elements in that workset.

Note that to find worksets we use a FilteredWorksetCollector (not a FilteredElementCollector) and a WorksetKindFilter to get only the user worksets (don’t want view, family, project standard worksets).

public void ViewWorksetIso()
{
    Document doc = this.ActiveUIDocument.Document;
    if (!doc.IsWorkshared)
        return;
    
    // get the 3d view type which is needed when creating 3d views
    ViewFamilyType vft = new FilteredElementCollector(doc)
        .OfClass(typeof(ViewFamilyType))
        .Cast<ViewFamilyType>()
        .FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);
    
    using (Transaction t = new Transaction(doc, "workset view isolation"))
    {
        t.Start();
        
        // loop through all worksets (but only User worksets)
        foreach (Workset wset in new FilteredWorksetCollector(doc).WherePasses(new WorksetKindFilter(WorksetKind.UserWorkset)))
        {
            // create a 3d view
            View3D view = View3D.CreateIsometric(doc, vft.Id);
            
            // set the name of the view to match the name of the workset
            view.Name = "WORKSET - " + wset.Name;
            
            // isolate elements in the view, using a filter to find elements only in this workset
            view.IsolateElementsTemporary(new FilteredElementCollector(doc).WherePasses(new ElementWorksetFilter(wset.Id)).Select(q => q.Id).ToList());
        }
        t.Commit();
    }
}
Advertisements

9 thoughts on “#RTCNA wish 7 granted! Isolated 3d view for each workset

  1. Harry,

    I appreciate the Granted Wishes, but I have a suggestion on #7.

    Wouldn’t it make more sense to create a 3D view where all worksets, except for one, are turned off? I really like the concept of this macro, but when I select elements that should be on another workset, and assign them to the correct workset, they remain visible. At this point, I have to delete the views and re-run the macro.

    Thanks, and keep up the good work!

  2. thanks so much for this. I had moved it over to my application and it was working but then had to rebuild my machine and now I’ve lost it. I keep getting an error when I build it

    } expected (CS1513) – C:\ProgramData\Autodesk\Revit\Macros\2015\Revit\AppHookup\RTC\Source\RTC\ThisApplication.cs:69,2

    • Yes that seems to be what the error suggests but I’m vutting and pasting from your page. And I’m essentially copying from “Public void..” down and pasting it in place.

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