Arcpy Exist Gives Inconsistent results

118
1
03-31-2020 11:35 AM
PaoloSucci
New Contributor II

Since upgrading from 10.2 to 10.6 one of my scripts no longer works when it tries to use the CollectEvents tool. It has an issue reaching one of the layers saying it doesn't exist.

Sure enough, arcpy.Exists() returns False BUT the layer is grabbed using ListLayers() and it is one of two layers. I notice that if the layer is copied in two data frames, ListLayers() will grab both layers, but Exists() will only return True for one of them.

I can reproduce this issue with a new document and completely different datasets:

Is this a known bug or am I doing something wrong?

Thanks in advance!

Tags (1)
0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

What you are showing/seeing with the example is expected, at least in terms of Esri's documentation.  Since you are not passing a dataframe object to ListLayers, you are getting the layers from all dataframes.  According to the Exists—Help | Documentation:

Layers in a stand-alone script and layers in an active map can be used as input to Exists.

So, ListLayers should list all layers (given your arguments) and Exists should only evaluate layers that are part of the second map.