Thursday, 26 March 2015

arcgis desktop - ArcPy saveACopy method saving copy of MXD to wrong path?


I have a script that looks through datasets in a geodatabase and copies a mxd document to a folder. The programs works, however it is saving the map documents to my desktop and not the specified folder on my desktop (PATH2). This is the code I have so far:


import arcpy
import os
PATH1 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFM.gdb"
PATH2 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\"
arcpy.env.workspace = PATH1
arcpy.env.overwriteOutput=True


zones = arcpy.ListDatasets("Zone*")

for zone in zones:
mxd = arcpy.mapping.MapDocument(r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\Complete Final Capstone Map\Complete Z2 Campus Map_Landscape1.mxd")
print zone
mxd.saveACopy(PATH2 + zone)

Answer



I would set the PATH2 variable this way:


PATH2 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT"


And then try this insead of mxd.saveACopy(PATH2 + zone):


newmxd = os.path.join (PATH2, zone + ".mxd")
mxd.saveACopy(newmxd)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...