Environment: ArcGIS Pro 2.5
ArcGIS Desktop Layout DLL version: 12.4.0.0
While trying to export and import the same layout, I am losing the map frame's map connection in the layout. If I export the layout and open it normally in ArcGIS Pro, the 'map frame - map' connection is preserved. But, when I do the same using the ArcGIS Pro SDK, the 'map frame-map' connection is lost.
<SPAN class="comment token">//Export the layout</SPAN>
Layout<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SaveAsFile</SPAN><SPAN class="punctuation token">(</SPAN>layoutFilePath<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">//Import the layout</SPAN>
Item importedProjectItem <SPAN class="operator token">=</SPAN> ItemFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Create</SPAN><SPAN class="punctuation token">(</SPAN>layoutFilePath<SPAN class="punctuation token">,</SPAN> ItemFactory<SPAN class="punctuation token">.</SPAN>ItemType<SPAN class="punctuation token">.</SPAN>PathItem<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
List<SPAN class="operator token"><</SPAN>LayoutProjectItem<SPAN class="operator token">></SPAN> layoutProjectItemsBeforeImport <SPAN class="operator token">=</SPAN> Project<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN>GetItems<SPAN class="operator token"><</SPAN>LayoutProjectItem<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Add the imported item to the current project</SPAN>
Project<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">AddItem</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>IProjectItem<SPAN class="punctuation token">)</SPAN>importedProjectItem<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Find the newly added layout project item</SPAN>
LayoutProjectItem importedLayoutProjectItem <SPAN class="operator token">=</SPAN> Project<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN>GetItems<SPAN class="operator token"><</SPAN>LayoutProjectItem<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>item <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="operator token">!</SPAN>layoutProjectItemsBeforeImport<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Contains</SPAN><SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Get the layout</SPAN>
newLayout <SPAN class="operator token">=</SPAN> importedLayoutProjectItem<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayout</SPAN><SPAN class="punctuation token">(</SPAN><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></SPAN><SPAN></SPAN></SPAN>
The imported layout (newLayout) does not contain the 'map frame - map' connection. ie. the map frame is empty instead of pointing to the actual map. Is this a bug with the SDK or am I doing something wrong here? Any insight would be appreciated. Thank you!