patrick.jurgens

dissappearing layers from Arc Tool menus

Discussion created by patrick.jurgens on Jan 9, 2014
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
CDP\cdp_differences
BG\bg_differences
COUSUB\ccd_differences
COUSUB\mcd_differences
PLACE\place_differences
CONCITY\concity_differences
UGA\uga_differences
ELSD\elsd_differences
SCSD\scsd_differences
UNSD\unsd_differences
SLDL\sldl_differences
SLDU\sldu_differences
CD\cd_differences
AIA\aial_differences
TBG\tbg_differences
TRIBSUB\aitsl_differences
ANRC\anrc_differences
SUBMCD\submcd_differences
#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 = []
        arcpy.SelectLayerByLocation_management(lyr,"INTERSECT",r"BG\bg_differences",'#',"NEW_SELECTION")
        for row in arcpy.SearchCursor(lyr):
            x.append(row.OBJECTID)
        arcpy.SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION")
        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
PLACE\place_differences
#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.
[ATTACH=CONFIG]30373[/ATTACH]
I am posting this in the Python section as well since applys there too.

Outcomes