I'm attempting to convert MXDs to APRXs using the MXD filenames in a stand alone script. I'm basically using this code from a prior post: How to assign name to map layer in APRX when importing from MXD?
I have a test folder with six MXDs in it. The script gets as far as beginning to loop through the folder but then throws an OSError on the first MXD. The error is pointing towards the importDocument line (line 14 below).
import arcpy
workspaceMXD = r"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
arcpy.env.overwriteOutput = True
mxdlist = arcpy.ListFiles("*.mxd")
aprx = arcpy.mp.ArcGISProject(r"C:\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX_tempdelete.aprx")
for mxd in mxdlist:
print("Importing: {0}".format(mxd.split("\\")[-1]))
aprx.importDocument(mxd,include_layout=True)
print("Currently {0} maps in Project file.".format(len(aprx.listMaps())))
aprx.listMaps()[-1].name = mxd.split("\\")[-1][:-4]
aprx.saveACopy(r"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder")
Error
Importing: Beecher_Unit_200U_B.mxd
Traceback (most recent call last):
File "C:\GISstaff\Jared\Python Scripts\ArcGISPro\MxdToAprx.py", line 14, in <module>
aprx.importDocument(mxd,include_layout=False)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 223, in importDocument
return convertArcObjectToPythonObject(self._arc_object.importDocument(*gp_fixargs((document_path, include_layout, reuse_existing_maps), True)))
OSError: Beecher_Unit_200U_B.mxd
If I import one MXD at a time and save it as an APRX as seen in the code sample on the the ArcGISProject page, it works fine. But, I'm working with multiple MXDs. Does anyone know what this error is referring to?