Hello ESRI community.
We ar willing to migrate or work from ArcMap to ArcGIS Pro. We have over 200 mxd we need to export to APRX. We are not motivated to do that manualy. We would rather use a python script to do so.
We got this in the web how ever, it doesn't work. My colleague and I are not python user so it's complcated.
Moreover we want that the mxd data not to stored into the gdb of the project but to the shapefile. All the MXD we have, have only 5 common shapefiles data on a specific folder. we want to keep the data sources where they currently are.
here is the script we started:
Solved! Go to Solution.
I don't believe .importDocument() moves or copies data sources. So if your MXD references shapefiles, the imported APRX map will reference the same data sources.
Yes, you can use propy.bat to execute the python script.
As far as the script itself, I would do something like below (not tested though).
import arcpy
import os
# User input for MXD directory
in_dir = r'C:\Path\To\MXDs' # Update this path
# Validate if the input directory exists
if not os.path.exists(in_dir):
print('Error: The specified directory does not exist.')
exit()
# Path to a blank ArcGIS Pro project (.aprx)
blank_aprx_path = r'C:\Path\To\Blank.aprx' # Update this path
# Using arcpy.da.Walk to traverse the directory for MXD files
for dirpath, dirnames, filenames in arcpy.da.Walk(in_dir, datatype='Map'):
for file in filenames:
if file.lower().endswith('.mxd'): # Filter only .mxd files
file_path = os.path.join(dirpath, file) # Full path to MXD
mxd_name = os.path.splitext(file)[0] # Remove .mxd extension
try:
# Create a ArcGISProject object from the blank template
aprx = arcpy.mp.ArcGISProject(blank_aprx_path)
# Import the MXD document
aprx.importDocument(file_path)
# Save a copy of the new APRX in the same folder
aprx.saveACopy(os.path.join(dirpath, f'{mxd_name}.aprx'))
print(f'Successfully converted: {file_path}')
except Exception as e:
print(f'Error converting {file_path}: {e}')
I don't believe .importDocument() moves or copies data sources. So if your MXD references shapefiles, the imported APRX map will reference the same data sources.
Yes, you can use propy.bat to execute the python script.
As far as the script itself, I would do something like below (not tested though).
import arcpy
import os
# User input for MXD directory
in_dir = r'C:\Path\To\MXDs' # Update this path
# Validate if the input directory exists
if not os.path.exists(in_dir):
print('Error: The specified directory does not exist.')
exit()
# Path to a blank ArcGIS Pro project (.aprx)
blank_aprx_path = r'C:\Path\To\Blank.aprx' # Update this path
# Using arcpy.da.Walk to traverse the directory for MXD files
for dirpath, dirnames, filenames in arcpy.da.Walk(in_dir, datatype='Map'):
for file in filenames:
if file.lower().endswith('.mxd'): # Filter only .mxd files
file_path = os.path.join(dirpath, file) # Full path to MXD
mxd_name = os.path.splitext(file)[0] # Remove .mxd extension
try:
# Create a ArcGISProject object from the blank template
aprx = arcpy.mp.ArcGISProject(blank_aprx_path)
# Import the MXD document
aprx.importDocument(file_path)
# Save a copy of the new APRX in the same folder
aprx.saveACopy(os.path.join(dirpath, f'{mxd_name}.aprx'))
print(f'Successfully converted: {file_path}')
except Exception as e:
print(f'Error converting {file_path}: {e}')
Hello Marshal,
Thanks you very much the script works well in our test phase.
Best regards,
Paul-Emmanuel
Best regards,
Paulo