One thing to note here is that mapping.MapDocument("CURRENT")
works only within ArcMap and refers to the current open MXD. With this in mind, is necessary that you pass the path to your MXD file as the parameter of mapping.MapDocument()
. Because you want to refer to multiple MXD files, you'll need to get the paths of all the MXD files and then iterate through them, doing your process for each one of them. Assuming you had all your MXD files in one folder, you can easily create a list of all the MXD files using glob
(no need to install it as it makes part of Python's standard library). Here is a snippet that should accomplish what you are looking after:
import glob
import arcpy.mapping as mapping
mxd_paths = glob.glob(r'C:\path to mxds\*.mxd')
layer = mapping.Layer(r"c: PATH TO LAYER FILE") # no need to define the layer each loop if it is the same for every MXD
for mxd_path in mxd_paths:
mxd = mapping.MapDocument(mxd_path)
df = mapping.ListDataFrames(mxd)[0]
mapping.AddLayer(df, layer, "TOP")
mxd.save() # this is very important; otherwise you won't be able to see the changes
You can run this script outside or within ArcMap and it will add the layer to your 20 MXD files.