ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapFrame Class / GetViewExtent Method
Example Version

GetViewExtent Method
Gets the current extent of the map frame view. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public Envelope GetViewExtent()

Return Value

ArcGIS.Core.Geometry.Envelope or null if the associated map is a scene
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks
The associated map must be a 2D map or null is returned
Example
SetAutoCameraFixedExtent
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Extent;

var mf_extent = mf.GetViewExtent();

var extent = EnvelopeBuilderEx.CreateEnvelope(
  400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
autoCamera.Extent = extent;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also