ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ElementFactory Class / CreateMapFrameElement Method
The parent element container
The map frame location (point), envelope, or polygon
The map (to be) associated with the frame (can be null)
An element name (optional)
Select after create flag (default is true) (optional)
Additional element properties (optional)
Example

In This Topic
    CreateMapFrameElement Method (ElementFactory)
    In This Topic
    Create a map frame element based on the input map frame polygon and map URI. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function CreateMapFrameElement( _
       ByVal elementContainer As IElementContainer, _
       ByVal frameOrLocation As Geometry, _
       ByVal map As Map, _
       Optional ByVal elementName As String, _
       Optional ByVal select As Boolean, _
       Optional ByVal elementInfo As ElementInfo _
    ) As MapFrame

    Parameters

    elementContainer
    The parent element container
    frameOrLocation
    The map frame location (point), envelope, or polygon
    map
    The map (to be) associated with the frame (can be null)
    elementName
    An element name (optional)
    select
    Select after create flag (default is true) (optional)
    elementInfo
    Additional element properties (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Empty or null geometry
    frameOrLocation - invalid geometry type
    elementContainer must be a layout or group element (on a layout)
    Remarks
    Graphic layers are not valid containers for map frames. If the element container is a Layout then the element gets added to the root level of the layout TOC at the top most position. If the element container is a GroupElement then it gets added to the group at the topmost position.
    If a point is provided as the frame geometry then a default extent will be applied.
    Example
    Create_MapFrame
    //Creates a new map frame and changes the camera's scale.
    
    //Constuct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D ll = new Coordinate2D(6.0, 8.5);
      Coordinate2D ur = new Coordinate2D(8.0, 10.5);
      //At 2.x - Envelope env = EnvelopeBuilder.CreateEnvelope(ll, ur);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
      //Reference map, create MF and add to layout
      MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
      Map mfMap = mapPrjItem.GetMap();
      //At 2.x - mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap);
      //         mfElm.SetName("New Map Frame"); 
      mfElm = ElementFactory.Instance.CreateMapFrameElement(layout, env, mfMap, "New Map Frame");
    
      //Set the camera
      Camera camera = mfElm.Camera;
      camera.Scale = 24000;
      mfElm.SetCamera(camera);
    });
    Create Map Frame and Set Camera
    //Create a map frame and set its camera by zooming to the extent of an existing bookmark.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5);
      Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5);
      //At 2.x - Envelope mf_env = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur);
      Envelope mf_env = EnvelopeBuilderEx.CreateEnvelope(mf_ll, mf_ur);
    
      //Reference map, create MF and add to layout
      MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>()
                           .FirstOrDefault(item => item.Name.Equals("Map"));
      Map mfMap = mapPrjItem.GetMap();
      Bookmark bookmark = mfMap.GetBookmarks().FirstOrDefault(
                            b => b.Name == "Great Lakes");
    
      //At 2.x - MapFrame mfElm =
      //                  LayoutElementFactory.Instance.CreateMapFrame(
      //                                             layout, mf_env, mfMap);
      //         mfElm.SetName("New Map Frame");
      //
      MapFrame mfElm = ElementFactory.Instance.CreateMapFrameElement(
                           layout, mf_env, mfMap, "New Map Frame");
    
      //Zoom to bookmark
      mfElm.SetCamera(bookmark);
    });
    Create Map Frame 1
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(2.0, 4.5);
    Coordinate2D ur = new Coordinate2D(4.0, 6.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Reference map, create MF and add to layout
    //var map = MapView.Active.Map;
    //var map = mapProjectItem.GetMap();
    //...
    
    MapFrame mfElm = ElementFactory.Instance.CreateMapFrameElement(
                                                    layout, env, map);
    Create Map Frame 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(4.0, 2.5);
    Coordinate2D ur = new Coordinate2D(7.0, 5.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Reference map, create MF and add to layout
    //var map = MapView.Active.Map;
    //var map = mapProjectItem.GetMap();
    //...
    MapFrame mfElm = ElementFactory.Instance.CreateMapFrameElement(
      layout, env.Center, map);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also