Is it possible to check for more than one layer at a time?
I would like to do this (pseudocode):
if arcpy.Exists(vriLyr AND rsltLyr AND forCovLyr):
<skip ahead>
else:
arcpy.SelectLayerByLocation_management(vriLyr, "INTERSECT", areaBoundary)
arcpy.SelectLayerByLocation_management(rsltLyr, "INTERSECT", areaBoundary)
arcpy.SelectLayerByLocation_management(forCovLyr, "INTERSECT", areaBoundary)
Any suggestions?
1 Answer 1
You can only pass one dataset at a time to arcpy.Exists
, but you just as easily can chain them together with and
:
if arcpy.Exists(vriLyr) and arcpy.Exists(rsltLyr) and arcpy.Exists(forCovLyr):
This can get pretty unwieldy once the number of layers starts to grow, so I'd suggest the equivalent:
if all(arcpy.Exists(lyr) for lyr in [vriLyr, rsltLyr, forCovLyr]):
answered May 17, 2017 at 21:18
-
Did not know about the all() function, like it!Hornbydd– Hornbydd2017年05月17日 22:12:29 +00:00Commented May 17, 2017 at 22:12
-
lang-py