2

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 17, 2017 at 20:45

1 Answer 1

7

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
2
  • Did not know about the all() function, like it! Commented May 17, 2017 at 22:12
  • any and all are pretty neat. Commented May 17, 2017 at 23:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.