2

I am using ArcGIS 10.4.1.

Can you let me know how I can Select/Highlight (I am not going to run any attribute query against the layer and this is just for visualization) all features listed under one specific Group layer?

For example I have a group layer called Streets_line and many features listed under it.

Can you let me know how I can highlight all of them in Current Map?

I already tried this

import arcpy    

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListLayers(mxd, "Streets_line")[0]
for dfs in arcpy.mapping.ListDataFrames(mxd):
    for lyr in arcpy.mapping.ListLayers(mxd, "Streets_line", dfs):
        arcpy.SelectLayerByAttribute_management (lyr, "NEW_SELECTION", "")

and

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListLayers(mxd, "Streets_line")[0]
for dfs in arcpy.mapping.ListDataFrames(mxd):
    for lyr in arcpy.mapping.ListLayers(mxd, "Streets_line", dfs):
        arcpy.SelectLayerByAttribute_management (lyr.name, "NEW_SELECTION", "")

but I am getting this error

Runtime error  Traceback (most recent call last):   File "<string>", line 6, in <module>   
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 7182, in SelectLayerByAttribute     
raise e ExecuteError: 
ERROR 000840: The value is not a Table View. 
ERROR 000840: The value is not a Raster Layer. 
ERROR 000840: The value is not a Mosaic Layer.

enter image description here

1
  • 1
    Have you used the code exactly as I have it in my answer? I don't understand why it would select features in every layer.
    – Midavalo
    Commented Jun 9, 2017 at 20:12

1 Answer 1

1

You are getting that error because it is trying to select features in your group layer (which is impossible). You need your loop to test that the layer you are selecting is not a group layer (using if not lyr.isGroupLayer) or even better, test that it is a feature layer (using if lyr.isFeatureLayer)

mxd = arcpy.mapping.MapDocument("CURRENT")
sl = arcpy.mapping.ListLayers(mxd, "Streets_line")[0]
for lyr in arcpy.mapping.ListLayers(sl):
    if lyr.isFeatureLayer: # Only run the selection if a feature layer
        arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION")
6
  • Thanks Midavalo but this selects all features in current maps doesn't matter if they are within ` "Streets_line"` group layer or not! Commented Jun 9, 2017 at 18:25
  • 1
    @user1106951 Are you sure? I have re-tested and for me it only selects features in layers within the group layer. Layers outside the group layer are not selected
    – Midavalo
    Commented Jun 9, 2017 at 18:31
  • Yeah , on my side it is selecting all the features in current map Commented Jun 9, 2017 at 19:03
  • 1
    @user1106951 Could you please edit your question to include a screenshot of your table of contents?
    – Midavalo
    Commented Jun 9, 2017 at 19:05
  • 2
    @user1106951 can you post the code you ran? I tested Midavalo code and it worked on my machine
    – Lou
    Commented Jun 9, 2017 at 19:36

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