ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / LayoutView Class / Active Property
Example

In This Topic
    Active Property (LayoutView)
    In This Topic
    Gets the active layout view.
    Syntax
    public static LayoutView Active {get;}
    Public Shared ReadOnly Property Active As LayoutView
    Remarks
    Returns null if there is no active layout view.
    Example
    LayoutViewClassExample1
    //This example references the active layout view.  Next it finds a couple of elements and adds them to a collection. 
    //The elements in the collection are selected within the layout view.  Finally, the layout view is zoomed to the
    //extent of the selection.
    
    // Make sure the active pane is a layout view and then reference it
    if (LayoutView.Active != null)
    {
      LayoutView lytView = LayoutView.Active;
      //Reference the layout associated with the layout view
      Layout lyt = await QueuedTask.Run(() => lytView.Layout);
    
      //Find a couple of layout elements and add them to a collection
      Element map1 = lyt.FindElement("Map1 Map Frame");
      Element map2 = lyt.FindElement("Map2 Map Frame");
      List<Element> elmList = new List<Element>();
      elmList.Add(map1);
      elmList.Add(map2);
    
      //Set the selection on the layout view and zoom to the selected elements
      await QueuedTask.Run(() => lytView.SelectElements(elmList));
      await QueuedTask.Run(() => lytView.ZoomToSelectedElements());
    }
    LayoutViewClassExample2
    // Make sure the active pane is a layout view and then reference it
    if (LayoutView.Active != null)
    {
      LayoutView lytView = LayoutView.Active;
      //Reference the layout associated with the layout view
      Layout lyt = await QueuedTask.Run(() => lytView.Layout);
    
      //Find a couple of layout elements and add them to a collection
      Element map1 = lyt.FindElement("Map1 Map Frame");
      Element map2 = lyt.FindElement("Map2 Map Frame");
      List<Element> elmList = new List<Element>();
      elmList.Add(map1);
      elmList.Add(map2);
    
      //Set the selection on the layout view and zoom to the selected elements
      await QueuedTask.Run(() => lytView.SelectElements(elmList));
      await QueuedTask.Run(() => lytView.ZoomToSelectedElements());
      return true;
    }
    return false;
    MapSeries_FindPageNumber
    //Return the page number that corresponds to the page name field for an index feature
    
    Layout layout = LayoutView.Active.Layout;
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      SpatialMapSeries SMS = layout.MapSeries as SpatialMapSeries;
      Row msRow = SMS.CurrentRow;
      System.Windows.MessageBox.Show(SMS.FindPageNumber(msRow.GetOriginalValue(msRow.FindField("NAME")).ToString()));
    });
    Reference the active layout view
    //Reference the active layout view.
    
    //Confirm if the current, active view is a layout view.
    //If it is, do something.
    LayoutView activeLayoutView = LayoutView.Active;
    if (activeLayoutView != null)
    {
      // do something
    }
    UnSelect elements on the LayoutView
    LayoutView layoutView = LayoutView.Active;
    //Unselect one element.
    var elementToUnSelectInView = layout.FindElements(new List<string>() { "MyPoint" }).FirstOrDefault();
    layoutView.UnSelectElement(elementToUnSelect);
    //Unselect multiple elements.
    var elementsToUnSelectInView = layout.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
    layoutView.UnSelectElements(elementsToUnSelect);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also