I want to retrieve a list of map objects from my current ArcGIS Pro 2.6 project.
The way I achieve that currently is so:
<SPAN class="keyword token">internal</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">GetMaps</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> mapPanes <SPAN class="operator token">=</SPAN> ProApp<SPAN class="punctuation token">.</SPAN>Panes<SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>IMapPane<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
List<SPAN class="operator token"><</SPAN>Map<SPAN class="operator token">></SPAN> uniqueMaps <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>Map<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> mapPane <SPAN class="keyword token">in</SPAN> mapPanes<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>mapPane<SPAN class="punctuation token">.</SPAN>MapView<SPAN class="punctuation token">.</SPAN>Map <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
uniqueMaps<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>mapPane<SPAN class="punctuation token">.</SPAN>MapView<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
Maps <SPAN class="operator token">=</SPAN> uniqueMaps<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Executing the method in a saved project (aprx) where I have nine map panes returns an IEnumerable<IMapPane> with a count of nine. However, line seven in the snippet above was introduced because the foreach loop was failing on the add-method (line 9) in some cases.
Debugging and playing with the project before executing the GetMaps() methode showed that map panes, that would return null for their map property in an as-is-project suddenly return a map if the map was activated before executing the GetMap() method.
How can I get rid of this behaviour and/ or is there a possibility to by-pass the issue?
Bests Thomas