A sheet contains views and a title block. When creating a sheet view with the ViewSheet.Create() method, a title block family symbol Id is a required parameter for the method. The Autodesk.Revit.Document TitleBlocks property contains all title blocks in the document. Choose one title block to create the sheet.
Code Region: ViewSheet.Create() |
public static ViewSheet ViewSheet.Create(Document document, ElementId titleBlockTypeId); |
The newly created sheet has no views. The Viewport.Create() method is used to add views. The Viewport class is used to add regular views to a view sheet, i.e. plan, elevation, drafting and three dimensional. To add schedules to a view, use ScheduleInstance.Create() instead.
Code Region: Add views to sheet |
public static Viewport Viewport.Create(Document document, ElementId viewSheetId, ElementId viewId, XYZ point); |
Each sheet has a unique sheet number in the complete drawing set. The number is displayed before the sheet name in the Project Browser. It is convenient to use the sheet number in a view title to cross-reference the sheets in your drawing set. You can retrieve or modify the number using the SheetNumber property. The number must be unique; otherwise an exception is thrown when you set the number to a duplicate value.
The following example illustrates how to create and print a sheet view. Begin by finding an available title block in the document (using a filter in this case) and use it to create the sheet view. Next, add a 3D view. The view is placed with its lower left-hand corner at the center of the sheet. Finally, print the sheet by calling the View.Print() method.
Code Region: Creating a sheet view |
private void CreateSheetView(Autodesk.Revit.DB.Document document, View3D view3D) { // Get an available title block from document IEnumerable<FamilySymbol> familyList = from elem in new FilteredElementCollector(document) .OfClass(typeof(FamilySymbol)) .OfCategory(BuiltInCategory.OST_TitleBlocks) let type = elem as FamilySymbol where type.Name.Contains("E1") select type; // Create a sheet view ViewSheet viewSheet = ViewSheet.Create(document, familyList.First().Id); if (null == viewSheet) { throw new Exception("Failed to create new ViewSheet."); } // Add passed in view onto the center of the sheet if (Viewport.CanAddViewToSheet(document, viewSheet.Id, view3D.Id)) { BoundingBoxUV sheetBox = viewSheet.Outline; double yPosition = (sheetBox.Max.V - sheetBox.Min.V) / 2 + sheetBox.Min.V; double xPosition = (sheetBox.Max.U - sheetBox.Min.U) / 2 + sheetBox.Min.U; XYZ origin = new XYZ(xPosition, yPosition, 0); Viewport viewport = Viewport.Create(document, viewSheet.Id, view3D.Id, origin); } // Print the sheet out if (viewSheet.CanBePrinted) { TaskDialog taskDialog = new TaskDialog("Revit"); taskDialog.MainContent = "Print the sheet?"; TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No; taskDialog.CommonButtons = buttons; TaskDialogResult result = taskDialog.Show(); if (result == TaskDialogResult.Yes) { viewSheet.Print(); } } } |
You may want to change the settings of the printer before printing a sheet. The API exposes the settings for the printer with the PrintManager class, and related Autodesk.Revit.DB classes:
Class |
Functionality |
Autodesk.Revit.DB.PrintManager |
Represents the Print information in Print Dialog (File->Print) within the Revit UI. |
Autodesk.Revit.DB.PrintParameters |
An object that contains settings used for printing the document. |
Autodesk.Revit.DB.PrintSetup |
Represents the Print Setup (File->Print Setup...) within the Revit UI. |
Autodesk.Revit.DB.PaperSize |
An object that represents a Paper Size of Print Setup within the Autodesk Revit project. |
Autodesk.Revit.DB.PaperSizeSet |
A set that can contain any number of paper size objects. |
Autodesk.Revit.DB.PaperSource |
An object that represents a Paper Source of Print Setup within the Autodesk Revit project. |
Autodesk.Revit.DB.PaperSourceSet |
A set that can contain any number of paper source objects. |
Autodesk.Revit.DB.ViewSheetSetting |
Represents the View/Sheet Set (File->Print) within the Revit UI. |
Autodesk.Revit.DB.PrintSetting |
Represents the Print Setup (File->Print Setup...) within the Revit UI. |
For an example of code that uses these objects, see the ViewPrinter sample application that is included with the Revit Platform SDK.