ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / IElementFactory Interface / CreateMapSurroundElement Method
The parent element container
The map surround frame envelope or center point
Associated surround properties
An element name (optional)
Select after create flag (default is true) (optional)
Additional element properties (optional)
Example

In This Topic
    CreateMapSurroundElement Method (IElementFactory)
    In This Topic
    Create a map surround element based on the geometry and associated map surround and element properties.
    Syntax

    Parameters

    elementContainer
    The parent element container
    frameOrLocation
    The map surround frame envelope or center point
    surroundInfo
    Associated surround properties
    elementName
    An element name (optional)
    select
    Select after create flag (default is true) (optional)
    elementInfo
    Additional element properties (optional)

    Return Value

    Remarks
    Graphic layers are not valid containers for surrounds. The frameOrLocation can be either a ArcGIS.Core.Geometry.MapPoint or ArcGIS.Core.Geometry.Envelope. A default extent will be calculated if a map point is provided (rather than an envelope).
    Example
    Create_ScaleBar
    //Create a scale bar for a specific map frame and assign a scale bar style item.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Reference a North Arrow in a style
      StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
      ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars("Double Alternating Scale Bar 1")[0];
    
      //Build geometry
      Coordinate2D center = new Coordinate2D(7, 8);
    
      //Reference MF, create north arrow and add to layout 
      MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
      if (mf == null)
      {
        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
        return;
      }
    
      //At 2.x -
      //ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm);
      //sbElm.SetName("New Scale Bar");
      //sbElm.SetWidth(2);
      //sbElm.SetX(6);
      //sbElm.SetY(7.5); 
    
      var sbInfo = new ScaleBarInfo()
      {
        MapFrameName = mf.Name,
        ScaleBarStyleItem = sbStyleItm
      };
      var sbElm = ElementFactory.Instance.CreateMapSurroundElement(
                                          layout, center.ToMapPoint(), sbInfo, "New Scale Bar") as ScaleBar;
      sbElm.SetWidth(2);
      sbElm.SetX(6);
      sbElm.SetY(7.5);
    });
    Create_NorthArrow
    //Create a north arrow for a specific map frame and assign a north arrow style item.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Reference a North Arrow in a style
      StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
      NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows("ArcGIS North 10")[0];
    
      //Build geometry
      Coordinate2D center = new Coordinate2D(7, 5.5);
    
      //Reference MF, create north arrow and add to layout 
      MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
      if (mf == null)
      {
        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
        return;
      }
      //At 2.x -
      //NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm);
      //arrowElm.SetName("New North Arrow");
      //arrowElm.SetHeight(1.75);
      //arrowElm.SetX(7);
      //arrowElm.SetY(6);
    
      var naInfo = new NorthArrowInfo()
      {
        MapFrameName = mf.Name,
        NorthArrowStyleItem = naStyleItm
      };
    
      var arrowElm = ElementFactory.Instance.CreateMapSurroundElement(
                                layout, center.ToMapPoint(), naInfo, "New North Arrow") as NorthArrow;
      arrowElm.SetHeight(1.75);
      arrowElm.SetX(7);
      arrowElm.SetY(6);
    });
    TableFrame_CreateNew
    //Create a new table frame on the active layout.
    
    Layout layout = LayoutView.Active.Layout;
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D rec_ll = new Coordinate2D(1.0, 3.5);
      Coordinate2D rec_ur = new Coordinate2D(7.5, 4.5);
      //At 2.x - Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur);
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Reference map frame
      MapFrame mf = layout.FindElement("Map Frame") as MapFrame;
    
      //Reference layer
      Map m = mf.Map;
      FeatureLayer lyr = m.FindLayers("GreatLakes").First() as FeatureLayer;
    
      //Build fields list
      var fields = new[] { "NAME", "Shape_Area", "Shape_Length" };
    
      //Construct the table frame
      //At 2.x - TableFrame tabFrame = LayoutElementFactory.Instance.CreateTableFrame(layout, rec_env, mf, lyr, fields);
      var surroundInfo = new TableFrameInfo()
      {
        FieldNames = fields,
        MapFrameName = mf.Name,
        MapMemberUri = lyr.URI
      };
      var tabFrame = ElementFactory.Instance.CreateMapSurroundElement(layout, rec_env, surroundInfo) as TableFrame;
    });
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also