Select to view content in your preferred language

How to check the ListLayers(Map) is Empty or not

1104
3
03-07-2011 02:23 PM
BruceGreen
Occasional Contributor
Hi guys
I am looking for a method to find out if the ListLayers id empty or not using arcpy.mapping

I appreciate if you ca give me an idea bout this

Thanks
Tags (2)
3 Replies
NiklasNorrthon
Frequent Contributor
layerlist = arcpy.mapping.ListLayers(...)
if layerlist:
     do_something()
else:
     handle_empty_layer_list()
0 Kudos
BruceGreen
Occasional Contributor
Thanks Niklas
I will check it and reply you the result
0 Kudos
RichardDaniels
Frequent Contributor

I know this is an old thread, but a working snip was never posted, so here you go!

TurnOffLayer.py

_________________

import arcpy

fileName=arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr=arcpy.mapping.ListLayers(mxd, fileName)

if lyr:
    if lyr[0].visible==True:
         lyr[0].visible=False
         arcpy.RefreshActiveView()

sys.argv[2]=True
arcpy.SetParameter(1,"True")

0 Kudos