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

957
3
03-07-2011 02:23 PM
BruceGreen
New Contributor III
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
Occasional Contributor III
layerlist = arcpy.mapping.ListLayers(...)
if layerlist:
     do_something()
else:
     handle_empty_layer_list()
0 Kudos
BruceGreen
New Contributor III
Thanks Niklas
I will check it and reply you the result
0 Kudos
RichardDaniels
Occasional Contributor III

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