ViewSheet.Create Method

ViewSheetCreate Method

Creates a new ViewSheet.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public static ViewSheet Create(
	Document document,
	ElementId titleBlockTypeId
)
Public Shared Function Create ( 
	document As Document,
	titleBlockTypeId As ElementId
) As ViewSheet
public:
static ViewSheet^ Create(
	Document^ document, 
	ElementId^ titleBlockTypeId
)
static member Create : 
        document : Document * 
        titleBlockTypeId : ElementId -> ViewSheet 

Parameters

document  Document
The document to which the ViewSheet will be added.
titleBlockTypeId  ElementId
The type id of the TitleBlock type which will be used by the new ViewSheet. For no TitleBlock, pass invalid element ID.

Return Value

ViewSheet
The new ViewSheet.
Exceptions
ExceptionCondition
ArgumentException The ElementId titleBlockTypeId does not correspond to a TitleBlock type. -or- document is not a project document.
ArgumentNullException A non-optional argument was null
ModificationForbiddenException The document is in failure mode: an operation has failed, and Revit requires the user to either cancel the operation or fix the problem (usually by deleting certain elements). -or- The document is being loaded, or is in the midst of another sensitive process.
ModificationOutsideTransactionException The document has no open transaction.
Example
private void CreateSheetView(Autodesk.Revit.DB.Document document, View3D view3D)
{

    // Get an available title block from document
    FilteredElementCollector collector = new FilteredElementCollector(document);
    collector.OfClass(typeof(FamilySymbol));
    collector.OfCategory(BuiltInCategory.OST_TitleBlocks);

    FamilySymbol fs = collector.FirstElement() as FamilySymbol;
    if (fs != null)
    {
        using (Transaction t = new Transaction(document, "Create a new ViewSheet"))
        {
            t.Start();
            try
            {
                // Create a sheet view
                ViewSheet viewSheet = ViewSheet.Create(document, fs.Id);
                if (null == viewSheet)
                {
                    throw new Exception("Failed to create new ViewSheet.");
                }

                // Add passed in view onto the center of the sheet
                UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2,
                                     (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);

                //viewSheet.AddView(view3D, location);
                Viewport.Create(document, viewSheet.Id, view3D.Id, new XYZ(location.U, location.V, 0));

                // 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();
                    }
                }

                t.Commit();
            }
            catch
            {
                t.RollBack();
            }
        }
    }
}
Private Sub CreateSheetView(document As Autodesk.Revit.DB.Document, view3D As View3D)

    ' Get an available title block from document
    Dim collector As New FilteredElementCollector(document)
    collector.OfClass(GetType(FamilySymbol))
    collector.OfCategory(BuiltInCategory.OST_TitleBlocks)

    Dim fs As FamilySymbol = TryCast(collector.FirstElement(), FamilySymbol)
    If fs IsNot Nothing Then
        Using t As New Transaction(document, "Create a new ViewSheet")
            t.Start()
            Try
                ' Create a sheet view
                Dim viewSheet__1 As ViewSheet = ViewSheet.Create(document, fs.Id)
                If viewSheet__1 Is Nothing Then
                    Throw New Exception("Failed to create new ViewSheet.")
                End If

                ' Add passed in view onto the center of the sheet
                Dim location As New UV((viewSheet__1.Outline.Max.U - viewSheet__1.Outline.Min.U) / 2, (viewSheet__1.Outline.Max.V - viewSheet__1.Outline.Min.V) / 2)

                'viewSheet.AddView(view3D, location);
                Viewport.Create(document, viewSheet__1.Id, view3D.Id, New XYZ(location.U, location.V, 0))

                ' Print the sheet out
                If viewSheet__1.CanBePrinted Then
                    Dim taskDialog As New TaskDialog("Revit")
                    taskDialog.MainContent = "Print the sheet?"
                    Dim buttons As TaskDialogCommonButtons = TaskDialogCommonButtons.Yes Or TaskDialogCommonButtons.No
                    taskDialog.CommonButtons = buttons
                    Dim result As TaskDialogResult = taskDialog.Show()

                    If result = TaskDialogResult.Yes Then
                        viewSheet__1.Print()
                    End If
                End If

                t.Commit()
            Catch
                t.RollBack()
            End Try
        End Using
    End If
End Sub

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

private void CreateSheetView(Autodesk.Revit.DB.Document document, View3D view3D)
{

    // Get an available title block from document
    IEnumerable<FamilySymbol>�familyList =�from�elem�innew�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();
        }
    }
}
Private Sub CreateSheetView(document As Autodesk.Revit.DB.Document, view3D As View3D)

    ' Get an available title block from document
    Dim collector1 As New FilteredElementCollector(document)
    collector1 = collector1.OfClass(GetType(FamilySymbol)).OfCategory(BuiltInCategory.OST_TitleBlocks)
    Dim familyList As IEnumerable(Of FamilySymbol)

    familyList = From elem In collector1
                 Let fstype = TryCast(elem, FamilySymbol)
                 Where fstype.Name.Contains("E1")
                 Select fstype


    ' Create a sheet view
    Dim viewSheet__1 As ViewSheet = ViewSheet.Create(document, familyList.First().Id)
    If viewSheet__1 Is Nothing Then
        Throw New Exception("Failed to create new ViewSheet.")
    End If

    ' Add passed in view onto the center of the sheet
    If Viewport.CanAddViewToSheet(document, viewSheet__1.Id, view3D.Id) Then
        Dim sheetBox As BoundingBoxUV = viewSheet__1.Outline
        Dim yPosition As Double = (sheetBox.Max.V - sheetBox.Min.V) / 2 + sheetBox.Min.V
        Dim xPosition As Double = (sheetBox.Max.U - sheetBox.Min.U) / 2 + sheetBox.Min.U

        Dim origin As New XYZ(xPosition, yPosition, 0)
        Dim viewport__2 As Viewport = Viewport.Create(document, viewSheet__1.Id, view3D.Id, origin)
    End If

    ' Print the sheet out
    If viewSheet__1.CanBePrinted Then
        Dim taskDialog As New TaskDialog("Revit")
        taskDialog.MainContent = "Print the sheet?"
        Dim buttons As TaskDialogCommonButtons = TaskDialogCommonButtons.Yes Or TaskDialogCommonButtons.No
        taskDialog.CommonButtons = buttons
        Dim result As TaskDialogResult = taskDialog.Show()

        If result = TaskDialogResult.Yes Then
            viewSheet__1.Print()
        End If
    End If
End Sub

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also