SetBoxCenter Method


Moves this viewport so that the center of the box outline (excluding the viewport label) is at a given point.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 22.0.0.0 (22.1.0.0)
Since: 2014

Syntax

C#
public void SetBoxCenter(
	XYZ newCenterPoint
)
Visual Basic
Public Sub SetBoxCenter ( _
	newCenterPoint As XYZ _
)
Visual C++
public:
void SetBoxCenter(
	XYZ^ newCenterPoint
)

Parameters

newCenterPoint
Type: Autodesk.Revit.DB XYZ
The desired center for the box outline.

Examples

Copy C#
public static void PlaceAlignedViewsAtLeftCorner(Document doc)
{
    FilteredElementCollector fec = new FilteredElementCollector(doc);
    fec.OfClass(typeof(ViewPlan));
    var viewPlans = fec.Cast<ViewPlan>().Where<ViewPlan>(vp => !vp.IsTemplate && vp.ViewType == ViewType.CeilingPlan);

    ViewPlan vp1 = viewPlans.ElementAt(0);
    ViewPlan vp2 = viewPlans.ElementAt(1);

    using (Transaction t = new Transaction(doc, "Place on sheet"))
    {
        t.Start();

        // Add two viewports distinct from one another
        ViewSheet vs = ViewSheet.Create(doc, ElementId.InvalidElementId);
        Viewport viewport1 = Viewport.Create(doc, vs.Id, vp1.Id, new XYZ(0, 0, 0));
        Viewport viewport2 = Viewport.Create(doc, vs.Id, vp2.Id, new XYZ(0, 5, 0));

        doc.Regenerate();

        // Calculate the necessary move vector to align the lower left corner
        Outline outline1 = viewport1.GetBoxOutline();
        Outline outline2 = viewport2.GetBoxOutline();
        XYZ boxCenter = viewport2.GetBoxCenter();
        XYZ vectorToCenter = boxCenter - outline2.MinimumPoint;
        XYZ newCenter = outline1.MinimumPoint + vectorToCenter;

        // Move the viewport to the new location
        viewport2.SetBoxCenter(newCenter);

        t.Commit();
    }
}
Copy VB.NET
Public Shared Sub PlaceAlignedViewsAtLeftCorner(doc As Document)
    Dim fec As New FilteredElementCollector(doc)
    fec.OfClass(GetType(ViewPlan))
    Dim viewPlans = fec.Cast(Of ViewPlan)().Where(Function(vp) Not vp.IsTemplate AndAlso vp.ViewType = ViewType.CeilingPlan)

    Dim vp1 As ViewPlan = viewPlans.ElementAt(0)
    Dim vp2 As ViewPlan = viewPlans.ElementAt(1)

    Using t As New Transaction(doc, "Place on sheet")
        t.Start()

        ' Add two viewports distinct from one another
        Dim vs As ViewSheet = ViewSheet.Create(doc, ElementId.InvalidElementId)
        Dim viewport1 As Viewport = Viewport.Create(doc, vs.Id, vp1.Id, New XYZ(0, 0, 0))
        Dim viewport2 As Viewport = Viewport.Create(doc, vs.Id, vp2.Id, New XYZ(0, 5, 0))

        doc.Regenerate()

        ' Calculate the necessary move vector to align the lower left corner
        Dim outline1 As Outline = viewport1.GetBoxOutline()
        Dim outline2 As Outline = viewport2.GetBoxOutline()
        Dim boxCenter As XYZ = viewport2.GetBoxCenter()
        Dim vectorToCenter As XYZ = boxCenter - outline2.MinimumPoint
        Dim newCenter As XYZ = outline1.MinimumPoint + vectorToCenter

        ' Move the viewport to the new location
        viewport2.SetBoxCenter(newCenter)

        t.Commit()
    End Using
End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was null
Autodesk.Revit.Exceptions InvalidOperationException The viewport is not on a sheet.

See Also