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?

6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.