0

I'm trying to write a script that looks into a database and lists all the datasets that begin with zone. The script then enters into a for loop and copies a map into each on the datasets listed. The code returned exit code 0 and it even prints the zone in the interactive window, but the map isn't copied into the respective datasets. This is the code I have so far:

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

zones = arcpy.ListDatasets("Zone*")
mxd = arcpy.mapping.MapDocument(r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\Complete Final Capstone Map\Complete Z2 Campus Map_Landscape1.mxd")
for zone in zones:
    print zone
    mxd.saveACopy(PATH2 + zone +  ".mxd")
1
  • I believe you need to os.path.join (PATH2) and (zone + ".mxd") in: mxd.saveACopy(PATH2 + zone + ".mxd")
    – phloem
    Jan 9, 2015 at 19:30

4 Answers 4

3

To my knowledge (I'm still using 10.1), it is not possible to save an MXD or LYR file into a geodatabase. Geodatabases, at least currently, are set up to store the data used in a map, but they are not set up to store the map documents themselves. MXD files still currently have to be stored as flat files in a folder. Therefore, you could, if desired, changed your code to save the MXDs in subfolders under your folder r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT" with the same names as the corresponding datasets, but you can not copy MXD files into the geodatabase itself.

That said, I found an ArcGIS Ideas proposal that would allow the functionality you are looking for, so if you really see a need for this functionality, you may want to vote for that idea and see if ESRI will add it in a future release. http://ideas.arcgis.com/ideaView?id=08730000000882e&returnUrl=%2Fapex%2FideaList%3Fc%3D09a300000004xET%26category%3DProduction%2BMapping%2B%2528PLTS%2529

3
  • I have changed the directory path to a folder now and not a geodatabse, but still no results Jan 9, 2015 at 18:25
  • Can you update the code in your question to reflect your changes?
    – nmpeterson
    Jan 9, 2015 at 18:29
  • i just updated it Jan 9, 2015 at 19:20
2

You can't save a map document .mxd file within a geodatabase for access within ArcMap--it has to be stored as a regular file in Windows. It is technically possible to save an .mxd file within a geodatabase when using Python because Windows uses a folder to represent a geodatabase .gdb. But it will be invisible to ArcMap.

If you're having trouble with arcpy.mapping stuff, a good way to test this on your own is to try to replicate your Python code in the ArcMap GUI first.

1
  • 2
    I agree that this (saving an MXD inside a GDB) is likely the issue, however an interesting aside is that you can save an MXD inside a file GDB from within ArcMap - I just did it.
    – phloem
    Jan 9, 2015 at 18:16
1

Your script makes no sense to me. You create a list of datasets where the name starts with Zone from you DFM GeoDatabase. This bit is OK. You then essentially attempt to copy the same MXD "Complete Z2 Campus Map_Landscape1.mxd" INTO the GeoDatabase. So lets say you have just one dataset called Zone123 you are trying to copy the MXD into C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFM.gdb\Zone123.mxd

You do not store MXD's in GeoDatabase that is bad practise and certainly the reason why its failing.

0
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
    newmxd = os.path.join (PATH2, zone + ".mxd")
    mxd.saveACopy(newmxd)

Not the answer you're looking for? Browse other questions tagged or ask your own question.