AnsweredAssumed Answered

importDocument() OSError

Question asked by jpilbeam Champion on Nov 25, 2019
Latest reply on Nov 27, 2019 by jpilbeam

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

#List MXDs in workspaceMXD
workspaceMXD = r"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
arcpy.env.overwriteOutput = True
mxdlist = arcpy.ListFiles("*.mxd")

#aprx project
aprx ="C:\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX_tempdelete.aprx")

for mxd in mxdlist:
    print("Importing: {0}".format(mxd.split("\\")[-1]))

    #the count of the maps
    print("Currently {0} maps in Project file.".format(len(aprx.listMaps())))

    #name the maps
    aprx.listMaps()[-1].name = mxd.split("\\")[-1][:-4]




Importing: Beecher_Unit_200U_B.mxd
Traceback (most recent call last):
  File "C:\GISstaff\Jared\Python Scripts\ArcGISPro\", line 14, in <module>
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\", 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?