AnsweredAssumed Answered

Does a certain layer exist in map?

Question asked by bulla_b on Aug 21, 2017
Latest reply on Aug 21, 2017 by UHarano-esristaff

Hi,

 

What is the best way to determine if a layer exists or not?  I have some code that runs on a specific layer, but I don't want Arc to crash if the layer doesn't exist when the user presses the button.

 

Can anyone suggest a check to go through before the code below runs that will check for the layers existence?  I would think evaluating MapView.Active.Map.FindLayers("GISWRKS1.WORKS.VLS_Points") to a boolean would work, but I can't seem to get it to.

 

                var vlsLayer = MapView.Active.Map.FindLayers("GISWRKS1.WORKS.VLS_Points").First() as BasicFeatureLayer;

                var selection = vlsLayer.GetSelection();

                IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();  //save the selected OBJECTIDs to a list.

 

Thanks!

Outcomes