Select to view content in your preferred language

Importing mxd into ARCGIS pro using python script

3875
6
10-12-2018 11:05 AM
AndrewDolch2
Occasional Contributor

I have created a script to import  multiple MXD 

import arcpy, os, datetime

workspaceMXD = "C:\\Users\\e087607\\Desktop\\"
arcpy.env.overwriteOutput = True

aprx = arcpy.mp.ArcGISProject("Current")
arcpy.env.workspace = workspaceMXD
listFiles = arcpy.ListFiles("*.mxd")

#Import MXD Files
for files in listFiles:
inputMXD = os.path.join(workspaceMXD, files)
print (inputMXD)
aprx.importDocument(inputMXD)
aprx.saveACopy("C:\\Users\\e087607\\Documents\\ArcGIS\\Projects\\import.arpx")

print ("MXD Files: " + str(listFiles) + " were updated at " + str(datetime.time))

I go to run it as normal and takes its time (doesn't run quickly) but none of the files I wanted to copy over showed up.   I followed the script example from ESRI word for word.   Am I doing something wrong?   Is there a different code to use?Please let me know 

Thanks Andrew 

0 Kudos
6 Replies
MichaelVolz
Esteemed Contributor

Can you provide a screenshot of the output of print statements when running your script?

Do you have a link showing the script example provided by ESRI?

0 Kudos
AndrewDolch2
Occasional Contributor

 

Does this help?

0 Kudos
MichaelVolz
Esteemed Contributor

I copied your script into the python window of an aprx that I named import just like you.  I then ran the script and it added maps named Layers, Layers1, and Layers2 as I imported 3 mxd files.  Did you try going to the Catalog pane to see of these maps were added.  You then need to right click on the maps in the Catalog pane and click on Open.

Now if you wanted the maps to have the name of the mxd you imported, you'll need to add some additional code.

0 Kudos
SimonKettle
Frequent Contributor

Can you give an example of the code required to import the MXD file names as Map View names? 

0 Kudos
AndrewDolch2
Occasional Contributor

Yes.  How come it did not pop up in the tool bar

MichaelVolz
Esteemed Contributor

Does your reply mean that the mxds were imported, but you just did not see them at first?

0 Kudos