Creates a new ViewSheet.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)
Since:
2013
Syntax
Return Value
The new ViewSheet.
Examples
CopyC#
private void CreateSheetView(Autodesk.Revit.DB.Document document, View3D view3D)
{
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
{
ViewSheet viewSheet = ViewSheet.Create(document, fs.Id);
if (null == viewSheet)
{
throw new Exception("Failed to create new ViewSheet.");
}
UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2,
(viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);
Viewport.Create(document, viewSheet.Id, view3D.Id, new XYZ(location.U, location.V, 0));
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();
}
}
}
}
CopyC#
private void CreateSheetView(Autodesk.Revit.DB.Document document, View3D view3D)
{
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;
ViewSheet viewSheet = ViewSheet.Create(document, familyList.First().Id);
if (null == viewSheet)
{
throw new Exception("Failed to create new ViewSheet.");
}
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);
}
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();
}
}
}
CopyVB.NET
Private Sub CreateSheetView(document As Autodesk.Revit.DB.Document, view3D As View3D)
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
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
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)
Viewport.Create(document, viewSheet__1.Id, view3D.Id, New XYZ(location.U, location.V, 0))
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
CopyVB.NET
Private Sub CreateSheetView(document As Autodesk.Revit.DB.Document, view3D As View3D)
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
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
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
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
Exceptions
See Also