ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / NorthArrowStyleItem Class
Members Example

In This Topic
    NorthArrowStyleItem Class
    In This Topic
    Represents a north arrow saved in a style.
    Object Model
    NorthArrowStyleItem ClassCIMNorthArrow Class
    Syntax
    public class NorthArrowStyleItem : StyleItem, System.ComponentModel.INotifyPropertyChanged  
    Public Class NorthArrowStyleItem 
       Inherits StyleItem
       Implements System.ComponentModel.INotifyPropertyChanged 
    Example
    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);
    });
    Create North Arrow From StyleItem 1
    //Create a north arrow using a style.
    
    //Search for a style project item by name
    StyleProjectItem arcgis2dStyles = Project.Current.GetItems<StyleProjectItem>()
                      .First(si => si.Name == "ArcGIS 2D");
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      NorthArrowStyleItem naStyleItem = arcgis2dStyles.SearchNorthArrows(
                    "ArcGIS North 13").FirstOrDefault();
    
      //Reference the map frame and define the location
      MapFrame newFrame = layout.FindElement("New Map Frame") as MapFrame;
      Coordinate2D nArrow = new Coordinate2D(6, 2.5);
    
      //Construct the north arrow
      //At 2.x - var newNorthArrow = LayoutElementFactory.Instance.CreateNorthArrow(
      //                        layout, nArrow, newFrame, naStyleItem);
    
      var naInfo = new NorthArrowInfo()
      {
        MapFrameName = newFrame.Name,
        NorthArrowStyleItem = naStyleItem
      };
      var newNorthArrow = ElementFactory.Instance.CreateMapSurroundElement(
                              layout, nArrow.ToMapPoint(), naInfo);
    });
    Create North Arrow From StyleItem 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D center = new Coordinate2D(7, 5.5);
    
    //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];
    
    //Reference MF, create north arrow and add to layout 
    //var mf = container.FindElement("New Map Frame") as MapFrame;
    var mf = layout.FindElement(MapFrameName) as MapFrame;
    var narrow_info = new NorthArrowInfo()
    {
      MapFrameName = mf.Name,
      NorthArrowStyleItem = naStyleItm
    };
    var arrowElm = (NorthArrow)ElementFactory.Instance.CreateMapSurroundElement(
      layout, center.ToMapPoint(), narrow_info) as NorthArrow;
    arrowElm.SetName("New North Arrow");
    arrowElm.SetHeight(1.75);
    arrowElm.SetX(7);
    arrowElm.SetY(6);
    How to search for north arrows in a style
    public Task<IList<NorthArrowStyleItem>> GetNorthArrowsFromStyleAsync(StyleProjectItem style, string searchString)
    {
      if (style == null)
        throw new System.ArgumentNullException();
    
      //Search for north arrows
      return QueuedTask.Run(() => style.SearchNorthArrows(searchString));
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Mapping.StyleItem
             ArcGIS.Desktop.Mapping.NorthArrowStyleItem

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also