AnsweredAssumed Answered

arcpy: get access to layer that's in group layer?

Question asked by helenchu on Sep 21, 2018
Latest reply on Sep 21, 2018 by helenchu


I created a model builder and scripted it out to python.  My issue is it only works if the layer is outside of group layer.  How can I modify it to works in both inside and outside of group layer?  Thank you very much for your help.  




import arcpy,sys, os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\GIS\MyGeodatabase.gdb"
mxd = arcpy.mapping.MapDocument("CURRENT")
layerName = 'street'
lyr = arcpy.mapping.ListLayers(mxd, layerName)[0]
fc = arcpy.GetParameterAsText(0)

Street = "Street"

selCount = 0
if lyr.getSelectionSet(): # If there are selected features
selCount = len(lyr.getSelectionSet())
arcpy.AddMessage("{0} has {1} features selected.".format(fc, selCount))
# Process: Copy Features
arcpy.CopyFeatures_management(Street , street_CopySelected, "", "0", "0", "0")