Hi everyone,
I will have to modify about 45 mxd projects and it will be very helpful if I can add a couple of new feature layers (located inside one file geodatabase) into all of them at once.
I will be doubly helpful if I can set the formatting in the script as well.
Have any of you done this before? I don't have anything to begin with because I'm not very good with python but I research quite a lot. I've found scripts to add many feature layers to one mxd, but I'm looking to have something that will run through all the mxd in a directory and add them without me opening each file.
Thanks in advance 🙂
Solved! Go to Solution.
This is what I've used to loop through a directory of MXDs to examine and/or edit them...
import os, arcpy
# set a directory you're interested in
workingDir = r'C:\Users\tlaue\Desktop\GISTutorial'
arcpy.env.overwriteOutput = True
# get a list of all the files in the directory
maps = os.listdir(workingDir)
for m in maps:
if m[-4:] == ".mxd":
mxd = arcpy.mapping.MapDocument(os.path.join(workingDir,m))
## DO SOMETHING HERE ##
mxd.save()
To add on to what Tom posted, create .lyr files for feature classes you want to add to the maps. If it's the same FCs on each one you should be able to add the .lyr file and resave/export your mxd.
If you have multiple FCs that will be using the same .lyr you can add the .lyr to your mxd and then reset the data source to whatever FC you want to use.
Sorry I can't add any code, the script I wrote that did this was for an old employer and I don't have access to it anymore.
This is what I've used to loop through a directory of MXDs to examine and/or edit them...
import os, arcpy
# set a directory you're interested in
workingDir = r'C:\Users\tlaue\Desktop\GISTutorial'
arcpy.env.overwriteOutput = True
# get a list of all the files in the directory
maps = os.listdir(workingDir)
for m in maps:
if m[-4:] == ".mxd":
mxd = arcpy.mapping.MapDocument(os.path.join(workingDir,m))
## DO SOMETHING HERE ##
mxd.save()
To add on to what Tom posted, create .lyr files for feature classes you want to add to the maps. If it's the same FCs on each one you should be able to add the .lyr file and resave/export your mxd.
If you have multiple FCs that will be using the same .lyr you can add the .lyr to your mxd and then reset the data source to whatever FC you want to use.
Sorry I can't add any code, the script I wrote that did this was for an old employer and I don't have access to it anymore.