I have the following code:
import arcpy.mapping as mapping
mxd = mapping.MapDocument("current")
print mxd.title
df = mapping.ListDataFrames(mxd)[0]
print df.name
layer = mapping.Layer(r"C:\path\clippedCountries.lyr")
print layer.name
mapping.AddLayer(df, layer,"TOP")
# Refresh things
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
And it works fine. However, if I try to use the absolute filepath to set the mapping variable (instead of "current") it doesn't work. Any ideas? I''m running the script through the ArcGIS 10.2 python window.
* update *
Interestingly if I use the full path name and add mxd.save() it works, so long as the mxd is not currently open in ArcGIS. Next time I open the mxd the layer is there.
If I try to do this with the mxd referenced in the filepath OPEN at the time I get
IOError: MapDocObject: Unable to save. Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.
Which I believe is due to a lock.
If I switch it back to "current" the lock vanishes and it will save and show the layer added in real time.