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).
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#List MXDs in workspaceMXD</SPAN>
workspaceMXD <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> workspaceMXD
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
mxdlist <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*.mxd"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#aprx project</SPAN>
aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"C:\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX_tempdelete.aprx"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> mxd <SPAN class="keyword token">in</SPAN> mxdlist<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Importing: {0}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\\"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
aprx<SPAN class="punctuation token">.</SPAN>importDocument<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN>include_layout<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#the count of the maps</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Currently {0} maps in Project file."</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#name the maps</SPAN>
aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">=</SPAN> mxd<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\\"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN>
aprx<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Error
Importing<SPAN class="punctuation token">:</SPAN> Beecher_Unit_200U_B<SPAN class="punctuation token">.</SPAN>mxd
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"C:\GISstaff\Jared\Python Scripts\ArcGISPro\MxdToAprx.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">14</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
aprx<SPAN class="punctuation token">.</SPAN>importDocument<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN>include_layout<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
File <SPAN class="string token">"C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">223</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> importDocument
<SPAN class="keyword token">return</SPAN> convertArcObjectToPythonObject<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">.</SPAN>_arc_object<SPAN class="punctuation token">.</SPAN>importDocument<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>gp_fixargs<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>document_path<SPAN class="punctuation token">,</SPAN> include_layout<SPAN class="punctuation token">,</SPAN> reuse_existing_maps<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
OSError<SPAN class="punctuation token">:</SPAN> Beecher_Unit_200U_B<SPAN class="punctuation token">.</SPAN>mxd<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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?