Turn layers off w/ arcpy.mapping

6954
4
11-11-2010 11:13 AM
tripplowe
New Contributor
Hey Folks,

I hope y'all can help me get a handle on using arcpy.mapping.  When I run the 4 lines below in the python window, the layers in the project are displayed.  But if I uncomment "lyr.visible = False" , nothing happens - I had hoped the layer would be turned off.  How would I code turning the layer off?

Thanks,
-Tripp

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
    print lyr.name
#    lyr.visible = False
0 Kudos
4 Replies
NiklasNorrthon
Occasional Contributor III
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
0 Kudos
tripplowe
New Contributor
Perfect.  Thanks.
0 Kudos
JeffBarrette
Esri Regular Contributor
Note:  the Refresh functions are only needed when referencing a map document using the "CURRENT" keyword.  Not all functions automatically refresh the current ArcMap application.

When referencing a map document via a system path, the refresh functions are not required.

Jeff
0 Kudos
wilwaters
New Contributor III

Hi Jeff Barrette I ran this script from IDLE but it did not affect the visibility status of any layers:

print "This script turns off the following layers:"

try:

    arcpy

except NameError:

    import arcpy

mxd = arcpy.mapping.MapDocument(r"S:\EF1784\EF1784_Common\GIS\CODE SNIPPETS\remove bing\EF1784_050_000_GIS_0101.mxd")

for lyr in arcpy.mapping.ListLayers(mxd):

    print lyr.name

    lyr.visible = False

mxd.save

When I run the script in this thread from the Python window in ArcMap there are no issues. What am I doing wrong?

0 Kudos