Hi Everyone,
I am new to programming ArcGIS Pro SDK with C# but have over 10 years experience in ArcObjects (ArcMap 10.X) with C# and am trying to convert one of our C# scripts that creates maps automatically. I have converted each function from the original code to Pro SDK functions. The code reads a text file to get a permit number and creates a map for that permit. Everything works great on the first permit but as soon as it goes to do the second permit, the code loses its reference to the MapView.
Using the first example from this ESRI GetMapView Method—ArcGIS Pro example, I created this function
public static MapView SetActiveMapView(Layout pageLayout)
{
LayoutView lytView = LayoutView.Active;
MapFrame mf_bmp = pageLayout.FindElement("LWDD Documents Map") as MapFrame;
MapView mv_bmp = mf_bmp.GetMapView(lytView);
return mv_bmp;
}
The code crashes with a "ACCESS DENIED" error on line MapView mv_bmp = mf_bmp.GetMapView(lytView);
It's probably something simple since I'm new to ArcGIS Pro SDK but I have been spinning my wheels on this for a couple of weeks and can't get past it. Can anyone point me in the right direction?
Which version of Pro 3x are you on?
The GetMapView method needs to be on the Main CIM thread. It needs to be run under the context of the QueuedTask. Like this:
//Reference the map frame and its map view
MapFrame mf_bmp = layout.FindElement("Map Frame") as MapFrame;
//On the worker thread
await QueuedTask.Run(() =>
{
MapView mv_bmp = mf_bmp.GetMapView(lytView);
if (mv_bmp != null) {
//Do something with the mapview
}
});
Sorry, forgot to include that in my post. I'm using Pro 3.3.
Thanks for your suggestion, I will give it a try and post back. My biggest learning curve right now is exactly what you are pointing out, I do not understand very well when a function has to be called with "await" versus not. Haven't been able to wrap my brain around that yet.