AnsweredAssumed Answered

Using a table in an array of layers

Question asked by Cep86 on Mar 10, 2016
Latest reply on Mar 11, 2016 by Cep86

I am running ArcMap 10.3.1, version 10.3.1.4959, on a Windows 7 machine.

 

I have a python script that grabs the layers within a map, and then applies a user input definition query to each of the feature classes.  I have recently added 2 database tables that I would also like for the tool to add the definition query to, but I am having trouble in figuring out how to reference the tables.

 

To reference the feature classes, I use the following code:

 

# Import system modules
import arcpy
import arcpy.mapping as map

# Set local variables
inputQuery = arcpy.GetParameterAsText(0)
mxd = map.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd)
lyrList = ["FC1", "FC2", "FC3", "FC4"]

# Execute definitionQuery
for lyr in layers:
    if lyr.name in lyrList:
        lyr.definitionQuery = defQuery

arcpy.RefreshActiveView()

 

Please note that the defQuery variable is acquired in a nested if/then statement, so I excluded the code, and the tool works just fine when not considering the two new database tables.  It grabs the four feature classes that are in the layer list, and then applies the definition query.

 

My problem is that I can't seem to replicate this process for tables.  The tables are located in the exact same SQL geodatabase, and they are both in the same version level in the map document.  I've tried to add the tables to the existing layer list, and I have also tried adding them to their own layer list aside from the feature classes and neither of them work.  One thing I did notice is that when I tested the code in the ArcMap Python Window, and I tried to print the layer list, all layers ranging from group layers to feature classes and even including the basemap layers and sublayers got printed just fine...with the exception of the tables, which did not print at all.  Is there some sort of limitation regarding database tables, or is there some other method that I must employ in order to grab them and apply the definition query to them?

 

Any help is much appreciated.

Outcomes