ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ScaleBar Class
Members Example

In This Topic
    ScaleBar Class
    In This Topic
    Represents a scale bar on a page layout. Represents a scale bar on a page layout
    Object Model
    ScaleBar ClassCoordinate2D StructureEnvelope ClassCIMElement ClassGeometry ClassIElementContainer InterfaceMapFrame Class
    Syntax
    Remarks
    There are currently no additional members but this class can be used to determine the type of MapSurround..
    Example
    Create Scale Bar
    {
      //Note: Must be on QueuedTask.Run
    
      //Build geometry
      Coordinate2D ll = new Coordinate2D(5.0, 6);
      Coordinate2D ur = new Coordinate2D(6.0, 7);
      Envelope sbEnv = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
      //Reference a Scale Bar in a style
      StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
                    .FirstOrDefault(item => item.Name == "ArcGIS 2D");
      ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars(
                   "Alternating Scale Bar 1")[0];
      //ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars(
      //                                   "Double Alternating Scale Bar 1")[0];
      //ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars(
      //                                    "Hollow Scale Bar 1")[0];
    
      //Create Scale Bar
      ScaleBarInfo sbInfo = new ScaleBarInfo()
      {
        MapFrameName = mapFrame.Name,
      };
    
      var sbElm = ElementFactory.Instance.CreateMapSurroundElement(
                                         layout, sbEnv, sbInfo) as ScaleBar;
    }
    Create Scale Line
    {
      //Note: Must be on QueuedTask.Run
      //Build geometry
      Coordinate2D ll = new Coordinate2D(5.0, 8);
      Coordinate2D ur = new Coordinate2D(6.0, 9);
      Envelope sbEnv = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
      //Reference a Scale Bar in a style
      StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
                                   .FirstOrDefault(item => item.Name == "ArcGIS 2D");
      ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars(
                                    "Scale Line 1")[0];
      //ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars(
      //                                           "Stepped Scale Line")[0];
      //ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars(
      //                                            "Scale Line 2")[0];
    
      //Create Scale Bar
      ScaleBarInfo sbInfo = new ScaleBarInfo()
      {
        MapFrameName = mapFrame.Name,
        ScaleBarStyleItem = sbStyleItm
      };
    
      var sbElm = ElementFactory.Instance.CreateMapSurroundElement(
                        layout, sbEnv, sbInfo, "ScaleBar Line") as ScaleBar;
    }
    Update a map surround
    {
      //Update a map surround.
      //Note: Must be on QueuedTask.Run
      // Reference and load the layout associated with the layout item
    
      // Reference a scale bar element by name
      MapSurround scaleBar = layout.FindElement("MyScaleBar") as MapSurround;
    
      // Reference a map frame element by name
      MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;
    
      if ((scaleBar != null) && (mf != null))
        //Set the scale bar to the newly referenced map frame
        scaleBar.SetMapFrame(mf);
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Layouts.Element
             ArcGIS.Desktop.Layouts.MapSurround
                ArcGIS.Desktop.Layouts.ScaleBar

    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also