1

I have an MXD as a template and about 650 folders. Each folder corresponds to a species.

What I want to do is to make an MXD (same as the template) in every folder of each species.

How to do this programmatically?

3
  • How is your species data arranged? In a single feature class or does each species has its own feature class? Are there multiple feature classes for each species? Do you want to change anything else about each map? Do you want to keep the same extent for each map? Commented Aug 17, 2015 at 15:03
  • In every folder there are 4 polygon shapefiles and 1 point shapefile. Every folder has the same amount and the same type of data. I don't want to change anything else. The extent for each map is the same. Commented Aug 17, 2015 at 15:22
  • It could be simple but depends of what we are working with. I am assuming that those folders contain data and you want to create Mxd in each one, such that the mxd will be specific to the folder that contains it. Do all the folders contain the same structure of data? Thank you! Commented Aug 17, 2015 at 15:27

1 Answer 1

2

This is just a pure Python solution. It assumes all your folders are within a root directory, and simply copies a specified MXD into each folder.

import os
import shutil

#change path to the MXD you'd like to copy
mxd_to_copy = "C:\\Projects\\Map.mxd"

#change to the root of where all the folders are stored
workspace = "C:\\Projects"

for dirpath, dirnames, filenames in os.walk(workspace):
    for folder in dirnames:
        if "gdb" not in folder:
           output_folder = os.path.join(dirpath, folder)

           shutil.copy2(mxd_to_copy, output_folder)

It'd probably be a good idea to put print output_folder in place of shutil.copy2(mxd_to_copy, output_folder) the first time to see where all the MXD will be copied.

Otherwise, I believe the only way to actually create a new MXD is through ArcObjects.

1
  • 1
    I saw this post (gis.stackexchange.com/questions/50714/…) to invoke ArcObjects via Python to create an mxd. Prob much easier to copy though and use relative sources so you don't need to source the copies.
    – Branco
    Commented Aug 17, 2015 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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