Saturday, 13 June 2015

arcgis 10.1 - Turning off layers in ArcMap via ArcPy?



I'm working on a script in ArcMap 10.1 that takes a screenshot and I need to know how to extinguish (turn off) a layer in my table of contents.



Answer



The Layer object has a read/write property, visible, that can be used to turn on/off layers.


This is some basic code that should get you started:


#A list of layer names that you want to be turned off.
names = [x,y,z,etc]

mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(, mxd, "Layers")[0]
layers = arcpy.mapping.ListLayers(mxd, "*", df)


for layer in layers:
if layer.name in names:
layer.visible = False

arcpy.RefreshTOC()
arcpy.RefreshActiveView()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...