I am trying to import multiple MXDs into an existing ArcGIS Pro project using arcpy.
When I run the code it completes successfully but when I open the ArcGIS Pro project there is nothing there. I changed the Pro Project variable to 'CURRENT' and inserted the code in ArcGIS Pro's Python terminal and it works fine. Just confused on why the script would run in ArcGIS Pro and not outside.
# Specify the mxd directory
mxdDir = r'C:\Users\rossch\Downloads\NS114_BasemapMXDs'
proProj = 'C:\Users\rossch\Downloads\ArcGISPro_MXDImport\ArcGISPro_MXDImport.aprx'
# Set workspace
arcpy.env.workspace = mxdDir
# List the mxds
mxds = arcpy.ListFiles('*.mxd')
aprx = arcpy.mp.ArcGISProject(proProj)
for mxd in mxds:
mxdFilePath = os.path.join(mxdDir, mxd)
aprx.importDocument(mxdFilePath)
This was the code I used outside ArcGIS Pro.
Solved! Go to Solution.
You don't save the aprx, so when the script runs, it doesn't retain anything, I suspect.
When you run it within Pro it probably loads, but if you don't save the project, they will vanish as well
see 'save' or saveACopy in
ArcGISProject—ArcGIS Pro | Documentation
You don't save the aprx, so when the script runs, it doesn't retain anything, I suspect.
When you run it within Pro it probably loads, but if you don't save the project, they will vanish as well
see 'save' or saveACopy in
ArcGISProject—ArcGIS Pro | Documentation
Thanks @DanPatterson. That did the trick. For some reason I assumed I didn't have to save the project through an import. Obviously I was wrong!
Have you added a map to your Pro project or checked in the Catalog under 'Maps', if available? Last I knew when you bring in an *.mxd with arcpy it doesn't open a map automatically.