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:
But I get this one no matter what I put in here (SearchNorthArrows("ArcGIS North 13")):
Solved! Go to Solution.
I tried it and receive this error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
naStyleItem was null.
that's why yours doesnt work then. Check your ArcGIS 2D style and why it doesnt contain a "ArcGIS North 13"
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);
});
I tried it and receive this error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
naStyleItem was null.
that's why yours doesnt work then. Check your ArcGIS 2D style and why it doesnt contain a "ArcGIS North 13"