Creates a new ViewSheet.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 27.0.4.0 (27.0.4.0)
Syntaxpublic 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| Exception | Condition |
|---|
| 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.
|
Exampleprivate 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();
}
}
}
}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();
}
}
}
See Also