1

Using ArcGIS 10.4.1 can you please 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 please 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.

Update:

enter image description here

  • 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 Jun 9 '17 at 20:12
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")
  • Thanks Midavalo but this selects all features in current maps doesn't matter if they are within ` "Streets_line"` group layer or not! – user1106951 Jun 9 '17 at 18:25
  • @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 Jun 9 '17 at 18:31
  • Yeah , on my side it is selecting all the features in current map – user1106951 Jun 9 '17 at 19:03
  • @user1106951 Could you please edit your question to include a screenshot of your table of contents? – Midavalo Jun 9 '17 at 19:05
  • 1
    @user1106951 can you post the code you ran? I tested Midavalo code and it worked on my machine – Lou Jun 9 '17 at 19:36

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.