Friday, 17 August 2018

arcpy - Importing MXD to ArcGIS Pro programmatically?


I have a problem with importing an MXD file to ArcGIS Pro programatically. I try to do this by using the following arcpy.mp code:


import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\test\blank.aprx")
aprx.importDocument(r"C:\test.mxd)
aprx.saveACopy(r"C:\test\filled.aprx")


When I launch ArcGIS Pro and open the resulting project file, no items in Contents can be visible. I tried to load the MXD file programatically into opened ArcGIS Pro instance by using the Python frame - also no items are visible in Contents after loading. For a final test, I tried to load this MXD by using GUI - and this works perfectly, all layers are visible in Contents pane when loaded.


What am I doing wrong?



Answer



To follow up on my comment, the code you posted does work, but does not automatically open the newly imported map.


I checked with members of the arcpy.mp team and at the time of writing there is no function or option on importDocument to automatically open the imported document. In time the functions might be enhanced (I've passed this feedback to the team)


You could investigate using the ProSDK. I know in the SDK there are options to open maps from a Project. This sample here might do what you want. Note, the addins are "inside the app", thus its a singular workflow. Where the arcpy.mp in a script is a more automated workflow (unless you wrote code to automate over multiple aprx/mxds). Depending on your situation one method might be more preferable than the other (arcpy.mp vs. ProSDK).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...