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

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

    Return Value

    ArcGIS.Core.Internal.CIM.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.0 or higher.
    See Also