How to import mpk files into ArcGIS Pro using Python?

888
3
12-06-2021 05:53 AM
AlkaRamnath
New Contributor III

Hi

I have a number of ArcMap map packages (.mpk files) that I need to import into ArcGIS Pro. I am using ArcGIS Pro 2.8.3 and want to use Python to import the .mpk files to save time. I have read on the ESRI Help at https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm that I can use ImportDocument to import ArcMap map (.mxd), globe (.3dd) and scene (.sxd) files into ArcGIS Pro. However, there is no mention of ArcMap map packages (.mpk files). I tried to test if importDocument will import a .mpk file using the code provided in ArcGISPro Example 1 listed on the page but I obtained an error message.

The code I have used is:

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprx.importDocument(r"C:\1\uMDM_Sanitation_Plan_2021\Sorting_Data\Boston Scheme1.mpk")
aprx.defaultGeodatabase = r"C:\1\uMDM_Sanitation_Plan_2021\uMDMData.gdb"
aprx.saveACopy(r"C:\1\uMDM_Sanitation_Plan_2021\uMDM_SpatialPlanning.aprx")

The error message obtained reads as follows:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 235, in importDocument
return convertArcObjectToPythonObject(self._arc_object.importDocument(*gp_fixargs((document_path, include_layout, reuse_existing_maps), True)))
OSError: C:\1\uMDM_Sanitation_Plan_2021\Sorting_Data\Boston Scheme1.mpk

I am new in using Python so I could be making a mistake in how I have entered the code.

Do you know how to import .mpk files into ArcGIS Pro using Python?

Thank you.

Regards,

Alka

 

0 Kudos
3 Replies
JoeBorgione
MVP Emeritus

I just took a look at the help topic Import An ArcMap Document and it looks like importing an ArcMap mpk file is a fairly rigorous task and I suspect there isn't an arcpy method available to do it.

That should just about do it....
0 Kudos
JoeBorgione
MVP Emeritus

I stand corrected.  I think....  Take a look at https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/extract-package.htm and see if you can make sense of it...

That should just about do it....
0 Kudos
AlkaRamnath
New Contributor III

Hi

Thank you for the two suggestions. It looks like you are correct as I will first need to extract all the map packages, then import all the mxds into ArcGIS Pro and then point each of them to the relevant features. This is beyond my arcpy skills but it should provide a good learning experience for me. In terms of deadlines however, the manual route may be quicker. I will have to see.

Again, thank you. I hope that you continue helping us after you retire.

0 Kudos