AnsweredAssumed Answered

ArcGISProject saveACopy()

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

At the end of this script that imports MXDs into an ArcGIS Pro Project I'm using the saveACopy function.

'''Import folder of MXD(s) into an ArcGIS Pro Project and save the project in a folder.

import arcpy, os

#List full path location of MXD(s) in workspaceMXD 
workspaceMXD = r"C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
mxdlist = arcpy.ListFiles("*.mxd")

#aprx project that MXD(s) are being imported into
aprx ="C:\gisfile\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX.aprx")

for mxd in mxdlist:
    arcpy.env.overwriteOutput = True
    fullpath = os.path.join(workspaceMXD, mxd)
    print("Importing: {}".format(fullpath))
    aprx.importDocument(fullpath) #import the MXD(s) into Pro

    #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]

    #save a copy of the project in the workspace folder


Importing: C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\Union_Elem_81_B.mxd
Currently 2 maps in Project file.
Importing: C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\ValleyView_Unit_365U_B.mxd
Currently 4 maps in Project file.
Importing: C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\WillCounty_Elem_92_B.mxd
Currently 6 maps in Project file.
Importing: C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\Wilmington_Unit_209U_B.mxd
Currently 8 maps in Project file.


It saves an APRX file from the workspace folder for each imported MXD. But, a copy of the map is imported in each consecutive project. So, as seen here and in the Test Folder, by the fourth saved APRX file maps for the other three projects are also there. 


That's why the file size of the APRXs increases by 400+ KB as the script loops through the folder.


I've also tried taking aprx.saveACopy(fullpath) out of the for loop. But, that only saves one APRX file with all maps in that one project.


How do I loop through the Test Folder and save a copy of the APRX file with it's corresponding map only?


As discussed at the bottom of my other post, ArcGISProject saveACopy seems only to allow full paths as a parameter.

importDocument() OSError