North Arrow not changing

337
3
Jump to solution
03-31-2023 08:15 AM
mstranovsky
New Contributor II

ArcGIS Pro 3.1 SDK addin is not changing the north arrow using this code:

// Add North Arrow
StyleProjectItem arcgis2dStyles = Project.Current.GetItems<StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
await QueuedTask.Run(() =>
{
NorthArrowStyleItem naStyleItem = arcgis2dStyles.SearchNorthArrows("ArcGIS North 13").FirstOrDefault();
MapFrame newFrame = layout_local.FindElement("New Map Frame") as MapFrame;
Coordinate2D nArrow = new Coordinate2D(3.6814, 0.6357);
var naInfo = new NorthArrowInfo()
{
MapFrameName = newFrame.Name,
NorthArrowStyleItem = naStyleItem
};
var newNorthArrow = ElementFactory.Instance.CreateMapSurroundElement(layout_local, nArrow.ToMapPoint(), naInfo);
});

I want this one:

mstranovsky_0-1680275630825.png

But I get this one no matter what I put in here (SearchNorthArrows("ArcGIS North 13")):

mstranovsky_1-1680275717844.png

 

 

0 Kudos
2 Solutions

Accepted Solutions
mstranovsky
New Contributor II

I tried it and receive this error:

 

System.NullReferenceException: 'Object reference not set to an instance of an object.'

naStyleItem was null.

View solution in original post

0 Kudos
CharlesMacleod
Esri Regular Contributor

that's why yours doesnt work then. Check your ArcGIS 2D style and why it doesnt contain a "ArcGIS North 13"

View solution in original post

0 Kudos
3 Replies
CharlesMacleod
Esri Regular Contributor

I cannot repro.

U can also try this as a workaround:

QueuedTask.Run(()=> {
 ...
 var naStyleItem = arcgis2dStyles.SearchNorthArrows("ArcGIS North 13").FirstOrDefault();
 //get the item definition
 var cim_na = naStyleItem.GetObject() as CIMMarkerNorthArrow;
 ...
 var naInfo = new NorthArrowInfo() {
   MapFrameName = newFrame.Name,
   //NorthArrowStyleItem = naStyleItem
 };
 var newNorthArrow = ElementFactory.Instance.CreateMapSurroundElement(
   layout_local, nArrow.ToMapPoint(), naInfo);
 //Apply the style
 var def = newNorthArrow.GetDefinition() as CIMMarkerNorthArrow;
 def.GraphicFrame = cim_na.GraphicFrame;
 def.PointSymbol = cim_na.PointSymbol;
 newNorthArrow.SetDefinition(def);

});
0 Kudos
mstranovsky
New Contributor II

I tried it and receive this error:

 

System.NullReferenceException: 'Object reference not set to an instance of an object.'

naStyleItem was null.

0 Kudos
CharlesMacleod
Esri Regular Contributor

that's why yours doesnt work then. Check your ArcGIS 2D style and why it doesnt contain a "ArcGIS North 13"

0 Kudos