dissappearing layers from Arc Tool menus

01-09-2014 07:18 AM
New Contributor III
I am working in version 10.1.
I have several layers stored in a file GDB\Feature Dataset.
All layers are added to an MXD and organized into Group Layers.
In ArcMap midway through a session Layers that are in the TOC no longer appear as options to input into ArcToobox tools.
The layers still appear in the TOC, I can still view them in the map and view their Attribute tables. However when I try to Geoprocess them with a tool that requires a Layer for input, they "don't exist".
If I close the map and re-open, then they "exist" again.

The dissapperance occurs after using arcpy.SelectLayerByLocation_management() tool in the Python immediate window.

Ultimately my goal is to use a Python AddIn to loop through several Layers in the current MXD Selecting by Location, reporting details about the selection, deselecting all, and then moving on to the next Layer on the list. (basically a push button option to spatially select multiple layers at once and get info about them in a summary listing).
The problem (as stated before) is that after the first Layer on the list completes successfully many of the subsequent layers on the work list have 'dissappeared' from the map document and are no longer accepted as valid input to the arcpy.SelectLayerByLocation_management() tool.
Restarting ArcMap in order to get my layers back is simply not an option because it would break the process and completely defeat the efficency benefits of using an AddIn.

Here is some code from the python immediate window (I added some comments '#...' after the fact:
>>> mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
diflyrs = arcpy.mapping.ListLayers(mxd,'*_differences',df)
ufc = diflyrs[1].name
>>> for lyr in diflyrs: print lyr.longName
#all layers in this list were found by arcpy.mapping.ListLayers(), so they were recognized as valid by arcObjects
>>> for lyr in diflyrs: 
    if not lyr.isBroken and lyr.name != ufc and int(str(arcpy.GetCount_management(lyr))):
        x = []
        for row in arcpy.SearchCursor(lyr):
        if x:
            print lyr.name, x
ccd_differences [1, 2]
#first layer on the list runs as expected.
Runtime error  Traceback (most recent call last):   File "<string>", line 4, in <module>   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 6559, in SelectLayerByLocation     raise e ExecuteError: ERROR 000368: Invalid input data.
#second layer on the list fails because it is not a layer?
>>> print lyr
#above is the long name for the layer that failed
#by the way, if I restart the MXD and alter the diflyrs list so that PLACE\place_differences runs first, it works, 
#but then the script fails when it reaches COUSUB\ccd_differences
#in case you wondered, layers CDP\cdp_differences and BG\bg_differences both get skiped by the initial if statement

After running the code above I took this screen shot attached which shows the PLACE\place_differences layer in the TOC along side an ArcToolbox tool which does not include it as a valid input. Before running the Python Script I used this exact tool to spatially select the PLACE\place_differences layer without any issue. Also even after 'breaking' the Layer I am still able to spatially select it by using the Select menu->Select by Location wizard.
I am posting this in the Python section as well since applys there too.
0 Kudos
0 Replies