ArcGIS Pro 2.6 API Reference Guide
CreateScaleBar Method (LayoutElementFactory)
Example 

ArcGIS.Desktop.Layouts Namespace > LayoutElementFactory Class : CreateScaleBar Method
Layout or GroupElement
Coordinate2D
Layout
Map
Creates a scale bar element on a layout from a 2D coordinate geometry. This method must be called on the MCT. Use QueuedTask.Run.
Syntax

Parameters

elementContainer
Layout or GroupElement
coord2D
Coordinate2D
mapFrame
Layout
styleItem
Map

Return Value

Returns a ScaleBar.
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Map has reached maximum graphics count limit of 4000 elements. One or more elements cannot be created.
Map has reached maximum graphics size limit of 10 MB. One or more elements cannot be created.
Remarks
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.
Example
//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;
  }
  ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm);
  sbElm.SetName("New Scale Bar");
  sbElm.SetWidth(2);
  sbElm.SetX(6);
  sbElm.SetY(7.5);
});
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 7

See Also

Reference

LayoutElementFactory Class
LayoutElementFactory Members