Moves this viewport so that the center of the box outline (excluding the viewport label) is at a given point.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)
Since:
2014
Syntax
C# |
---|
public void SetBoxCenter(
XYZ newCenterPoint
) |
Visual Basic |
---|
Public Sub SetBoxCenter ( _
newCenterPoint As XYZ _
) |
Visual C++ |
---|
public:
void SetBoxCenter(
XYZ^ newCenterPoint
) |
Examples
CopyC#
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();
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();
Outline outline1 = viewport1.GetBoxOutline();
Outline outline2 = viewport2.GetBoxOutline();
XYZ boxCenter = viewport2.GetBoxCenter();
XYZ vectorToCenter = boxCenter - outline2.MinimumPoint;
XYZ newCenter = outline1.MinimumPoint + vectorToCenter;
viewport2.SetBoxCenter(newCenter);
t.Commit();
}
}
CopyVB.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()
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()
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
viewport2.SetBoxCenter(newCenter)
t.Commit()
End Using
End Sub
Exceptions
See Also