- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to align views on a sheet using their cropbox, and not their 'viewport extents' as those are influenced by annotations.
Prior to Revit 2023, the trick was to hide all the annotations, so that the 'viewport extents' matches the cropbox, align the viewports and then re-able the annotations again.
But Revit 2023 got two new methods (https://thebuildingcoder.typepad.com/blog/2022/04/whats-new-in-the-revit-2023-api.html#4.2.6.2) that look like they should allow us to do this more efficiently.
This is what I have so far:
AlignViewPortsVertically:
public void AlignViewPortsVertically(List<View> viewsToAlign, View referenceView )
{
BoundingBoxXYZ referenceBoundingBox = RevitUtility.GetProjectedCropBoxOnSheet(referenceView);
foreach ( View view in viewsToAlign )
{
BoundingBoxXYZ viewBoundingBox = RevitUtility.GetProjectedCropBoxOnSheet(view);
double deltaX = referenceBoundingBox.Max.X - viewBoundingBox.Max.X;
double deltaXScaled = deltaX;
Viewport viewport = RevitUtility.GetViewPortOfView(view.Id);
RevitUtility.MoveViewPort(viewport, deltaXScaled, 0);
}
}
GetProjectedCropBoxOnSheet:
static public BoundingBoxXYZ GetProjectedCropBoxOnSheet(View view)
{
Viewport viewport = GetViewPortOfView(view.Id);
XYZ referenceMin = view.CropBox.Min;
XYZ referenceMax = view.CropBox.Max;
Transform transform = viewport.GetProjectionToSheetTransform();
XYZ minProjected = transform.OfPoint(referenceMin);
XYZ maxProjected = transform.OfPoint(referenceMax);
BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();
boundingBoxXYZ.Min = minProjected / view.Scale;
boundingBoxXYZ.Max = maxProjected / view.Scale;
return boundingBoxXYZ;
}
However, the views don't exactly align. See the image attached. Anyone have any ideas what I am doing wrong?
Solved! Go to Solution.