Select to view content in your preferred language

Arcpy Import MXD into ArcGIS Pro Project

1541
3
Jump to solution
11-30-2022 11:35 AM
ChrisJRoss13
New Contributor III

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. 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
ChrisJRoss13
New Contributor III

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!

0 Kudos
JaredPilbeam2
MVP Regular Contributor

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.

JaredPilbeam2_1-1669838618343.png

0 Kudos