Select to view content in your preferred language

Using a table in an array of layers

2157
2
Jump to solution
03-10-2016 02:00 PM
CoyPotts1
Deactivated User

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.

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

Tables showing in the table of contents are not "Layers", they are "TableViews". Access them via arcpy.mapping.ListTableViews(mxd)

View solution in original post

2 Replies
DarrenWiens2
MVP Honored Contributor

Tables showing in the table of contents are not "Layers", they are "TableViews". Access them via arcpy.mapping.ListTableViews(mxd)

CoyPotts1
Deactivated User

Perfect!  I figured it was something basic and just some other method, but I couldn't find anything in searching for it.  Thanks for the answer, Darren!

0 Kudos