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: 2015.0.0.0 (2015.0.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();
    }
}

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

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →