AnsweredAssumed Answered

ArcGIS Pro SDK - Select Layer regardless if it is in a Group Layer or not.

Question asked by MBDriscoll Champion on Feb 2, 2018
Latest reply on Feb 2, 2018 by MBDriscoll

I am trying to create a Map Tool where it only selects features in my "Parcels" layer.  Some users will have the "Parcels" layer inside a Group Layer in the Map and some will not.



var parcellayer = (MapView.Active.Map.Layers.First(layer => layer.Name.Equals("Parcels")) as FeatureLayer);

This works well if the layer is directly in the Map, but will crash if the layer is in a Group Layer in the Map.


I have yet to figure out how to use a layer within a Group Layer in the same manner, simply because it is not what I am after.


According to ProConcepts Map Authoring · Esri/arcgis-pro-sdk Wiki · GitHub , Working with Map Members, one should use FlattenedList because "Should you need to get a list without group layers hierarchy, use Map.GetLayersAsFlattenedList() method". 


When I do this, nothing happens when I try and use the new Map Tool



var parcellayer = (MapView.Active.Map.GetLayersAsFlattenedList().Where(layer => layer.Name.Equals("Parcels")) as FeatureLayer);


I want to be able to make a Select Map Tool where it will select the "Parcels" layer regardless of if it is in a Group Layer or not.




To add more confusion.  I can run a stand alone Python Script within Pro and it will not matter if a feature layer is in a Group layer or not.



selectPar = pm.SelectLayerByLocation("Parcels","WITHIN_A_DISTANCE",ZoneCaseFeat,"1000 Feet","NEW_SELECTION")


But if I run this same exact Python script from within .NET I have to put the Group in there first.



selectPar = pm.SelectLayerByLocation(r"GroupLayerName\Parcels","WITHIN_A_DISTANCE",ZoneCaseFeat,"1000 Feet","NEW_SELECTION")


But if I do this and run the Python script from within .Net it will work fine in or out of a group! 



aprx ="CURRENT")
m = aprx.listMaps("Layers")[0]
ParcelsLayer = m.listLayers("Parcels")[0]
selectPar = pm.SelectLayerByLocation(ParcelsLayer,"WITHIN_A_DISTANCE",ZoneCaseFeat,"1000 Feet","NEW_SELECTION")