2

I can use the code:

for lyr in arcpy.mapping.ListLayers(dataframe):
    arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")

to deselect features in each layer in my map. However, the above does not deselect tables in my map, or even attempt to. I have three layers and two tables, the layers deselect fine, but the tables are ignored. Also, the following code:

for tbl in arcpy.mapping.ListTableViews(df):
    arcpy.TableSelect_analysis(tbl, "CLEAR_SELECTION")

crashes every time with the error:

Error 000210: Cannot create output CLEAR_SELECTION

and in addition the online reference table for table select: http://pro.arcgis.com/en/pro-app/tool-reference/analysis/table-select.htm does not include directions on deselecting from a table. What is the proper syntax to use for the TableSelect_analysis to deselect everything?

5

You should use the Select Layer by Attribute tool to remove any selection, even with table views.

This tool works on layers or table views in the table of contents, and also on layers or table views created in models and scripts using the Make Feature Layer or Make Table View tools.

So in your code, use:

for tbl in arcpy.mapping.ListTableViews(dataframe):
    arcpy.SelectLayerByAttribute_management(tbl, "CLEAR_SELECTION")

Please see the link for more information.

  • I edited the question to try to address your answer, but the exact lines of your code are already in my code, and the tables do not deselect. I am not sure why, after reading the documentation you cite it seems they should be. – Craig T Aug 22 '17 at 13:53
  • How have you used the ListTableViews function? Does this correctly identify your tables? Have you created Table Views of your table? – MacroZED Aug 22 '17 at 13:55
  • 1
    isn't tbl instead of lyr ? try to print tables names to make sure – radouxju Aug 22 '17 at 13:56
  • Ha! Wow, thats a rookie error! :) code edited – MacroZED Aug 22 '17 at 13:56
  • and you are correct, I was not using ListTableViews(). Thanks. – Craig T Aug 22 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.