AnsweredAssumed Answered

Arcpy.Exists Fails On Existing Layers

Question asked by bwcoleman18_1 on Feb 26, 2015
Latest reply on Feb 26, 2015 by bwcoleman18_1

I am running into an issue where the `arcpy.Exists()` function returns a `false` for a known good layer in the python interactive window.  We are using a map document template for the layers set up in the Table of Contents.



I usually would drag the layer from the Table Of Contents into the interactive window so it shows like `r'Work Layers\Replacement Tree'` since it is part of a group in the Table of Contents.  If I manually add in the data instead of use a template and resource the layers, the `arcpy.Exists()` function works and returns `true`, but on occasion, it will return a `false`.



When it returns `false`, I can check the layer's source, navigate to the location and specified feature class, and see that it is there.  I can add it in manually and run it, too. 



For some reason, it seems using an existing map document as a template and resourcing the Table of Contents breaks this on occasion.  The code I am using is a bit more complex than the `arcpy.Exists()`, but I have narrowed it down to that being the issue.  My code throws an exception saying a particular layer doesn't exist so that is the easiest way to troubleshoot.



I have even gone as far as to drag multiple layers from the Table Of Contents into a list in the interactive window and iterate over it with `arcpy.Exists()` to the same result of `false`.



I can set the workspace to the file geodatabase we're using and the using the feature class name (ie. `layer = 'Replacement Tree'`) links to the correct feature class.



Is there a bug or a disconnect somewhere when using a map document as a template and resourcing the data from the Table of Contents to the python interactive window so that layers (which show up on the data frame, too!) aren't connected as if they were added in manually?


Also posted to: file geodatabase - Arcpy.Exists Fails On Existing Layers - Geographic Information Systems Stack Exchange