8

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?

  • 3
    I just used your code and it works fine for me -- My guess is you need to manually open the map. In the Project pane, expand Maps, do you see your imported MXD? Double click it. – KHibma Nov 4 '15 at 14:34
  • Thank you, yes my MXD is there. Is there a way to open automatically this MXD when the project is started? Of course in terms of doing so programatically, so that user does not need to perform this action manually? – Konrad Nov 4 '15 at 15:03
4

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.