I tried this standalone script to turn off all layers in the MXD:
print "This script turns off the following layers:"
try:
arcpy
except NameError:
import arcpy
mxd = arcpy.mapping.MapDocument(r"PATH")
for lyr in arcpy.mapping.ListLayers(mxd):
print lyr.name
lyr.visible = False
mxd.save
It is adapted from the script mentioned for the Python window here:
https://geonet.esri.com/thread/16415
The standalone one I created for IDLE from this, above, did not affect the visibility status of any layers when I opened the MXD afterward to check. This is strange because running the same script within the Python window turned off all the layers for me.
Any clues?
try/except
import arcpy
bit at the start of your code. I believe that if a module is already imported, python just ignores a second import of the same module. Thus, you can simply useimport arcpy
and get the same effect. Is there a reason I'm missing for why thetry/except
?