ArcGIS Pro Unit Testing, loading LayoutView problem

171
1
07-20-2021 11:21 AM
EricChang3721
New Contributor

Recently we are working on unit testing on our ArcGIS Pro plug-in/add-in application. We are referring the Esri's demo method, (https://github.com/Esri/arcgis-pro-sdk/wiki/ProGuide-Regression-Testing). We have a problem getting the LayoutView.

 

We can load the project file (.aprx) using the following code:

 

Project project = Project.OpenAsync(@"C:\Users\Administrator\Documents\files\test.aprx").Result;

QueuedTask.Run(() =>
{
_map = project.GetItems<MapProjectItem>().Where(x => x.Name.Equals("Map")).FirstOrDefault().GetMap();
_layers = _map.GetLayersAsFlattenedList();

_layoutProjItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout"));

_layout = _layoutProjItem.GetLayout(); //Worker thread

}).Wait();

 

But we cannot get LayoutView. For example, 

 

PaneCollection panes = ProApp.Panes;
ILayoutPane layoutPane = panes.FindLayoutPanes(_layout).FirstOrDefault();

 

layoutPane.LayoutView always returns null.

 

While We know in ArcGIS Desktop, like 10.*, we can get/initialize everything for example,

Get Mxd file (location of the mxd file) 

Get MapDocument 

Get PageLayout 

Set pageLayout as ActiveView. 

 

My Question is , in unit test, ArcGIS Pro can get LayoutView ? How to get the LayoutView in the Unit test.

 

thanks

Eric

0 Kudos
1 Reply
EricChang3721
New Contributor

In clarifying, we were able to retrieve a LayoutView instance, but it appears uninitialized. layoutPane.LayoutView.IsReady is always false and the Extent and ActiveMapFrame properties are null, etc. Our need is to access the map frames in the layout, and specifically that we need to call MapFrame.GetMapView() on each one.

Thanks

Eric

0 Kudos