Create a View/Sheet Set

public void CreateSheetSet()
    Document doc = this.ActiveUIDocument.Document;

    // create a new ViewSet - add views to it that match the desired criteria
    ViewSet myViewSet = new ViewSet();
    string match = "S";
    foreach (ViewSheet vs in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>()
             .Where(q => q.SheetNumber.Contains(match)))

    // get the PrintManger from the current document
    PrintManager printManager = doc.PrintManager;

    // set this PrintManager to use the "Selected Views/Sheets" option
    printManager.PrintRange = PrintRange.Select;

    // get the ViewSheetSetting which manages the view/sheet set information of current document
    ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

    // set the views in this ViewSheetSetting to the newly created ViewSet
    viewSheetSetting.CurrentViewSheetSet.Views = myViewSet;

    if (myViewSet.Size == 0)
        TaskDialog.Show("Error", "No sheet numbers contain '" + match + "'.");

    using (Transaction t = new Transaction(doc,"Create ViewSet"))
        string setName = "'" + match +"' Sheets";
            // Save the current view sheet set to another view/sheet set with the specified name.
        // handle the exception that will occur if there is already a view/sheet set with this name
        catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            TaskDialog.Show("Error", setName + " is already in use");
    TaskDialog.Show("View Set", myViewSet.Size + " sheets added to set");

13 thoughts on “Create a View/Sheet Set

  1. Your brilliant! I was looking for a way to do exactly this. But I was getting confused between all the ViewSet, ViewSheetSet, ViewSheetSets, and SheetSettings classes. Thanks!

  2. Harry,

    In this section:

    // handle the exception that will occur if there is already a view/sheet set with this name
    catch (Autodesk.Revit.Exceptions.InvalidOperationException)
    TaskDialog.Show(“Error”, setName + ” is already in use”);

    Is it possible to get the code to update (or ask if you want to update) the sheet set with the new myViewSet so that if more sheets are added it can be updated easily? I’m thinking you would use the ViewSheetSetting.Delete method and then add it back. Thanks!

  3. Harry amazing methods, however i tried to develop it to make it suites my needs,, but i am still can’t get it right with the ViewSheetSetting.Delete method… can you please teach me how to call for a set and delete it? also what is the different between dispose and delete?

    • The ViewSheetSet class is a sub-class of Element, so you can get the elementId of the ViewSheetSet and then call the Document.Delete Method (ElementId). Dispose is for .NET memory management and is something you will probably never need to use.

  4. Hello,

    Very interesting solution.

    It´s possible to select via code to create sets using the sheet size (maybe using the name of type)?

    Thank you in advance.

  5. Admiral Mattison:

    I can understand if you’ve retired from coding for Revit, after that program’s owners ‘flattered’ you last month … I’d be very disgusted …

    However, if you haven’t retired, perhaps you can make an adjustment to this macro you have, then put the thing on Exchange, and copyright it.

    In Revit, we can make a special schedule called a Sheet List, which is just a schedule of sheets. Often, we make these sheet lists for drawing revisions, and it works well. However, once the Sheet List is made, and we want to print out that set of drawings, we have to manually add those sheets to a Sheet Set under the Print function. Is there any way to write a routine that will generate a Sheet Set (for printing) from a Sheet List?

  6. Hi Harry,
    I have created an add-in that collects ViewSheets and renumbers them. Unfortunately after the renumber operation the numbers have changed in the sheet properties and not in the project browser. I have tried to use doc.Regenrate(); This has no affect. Also If I renumber a sheet manually they update to the sheet numbers created using an add-in

Leave a Reply

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

You are commenting using your 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