<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Does a certain layer exist in map? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823449#M2926</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the best way to determine if a layer exists or not? &amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone suggest a check to go through before the code below runs that will check for the layers existence? &amp;nbsp;I would think evaluating &lt;SPAN style="color: #2b91af; font-size: 9.5pt;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN style="color: black; font-size: 9.5pt;"&gt;.Active.Map.FindLayers(&lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 9.5pt;"&gt;"GISWRKS1.WORKS.VLS_Points"&lt;/SPAN&gt;&lt;SPAN style="color: black; font-size: 9.5pt;"&gt;) to&amp;nbsp;&lt;/SPAN&gt;a boolean &lt;SPAN style="font-size: 9.5pt; color: black;"&gt;would work, but I can't seem to get it to.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt; vlsLayer = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;.Active.Map.FindLayers(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #a31515;"&gt;"GISWRKS1.WORKS.VLS_Points"&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;).First() &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;BasicFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt; selection = vlsLayer.GetSelection();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;IReadOnlyList&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;long&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;gt; selectedOIDs = selection.GetObjectIDs();&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: green;"&gt;//save the selected OBJECTIDs to a list.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; color: green;"&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 21 Aug 2017 18:02:26 GMT</pubDate>
    <dc:creator>BrianBulla</dc:creator>
    <dc:date>2017-08-21T18:02:26Z</dc:date>
    <item>
      <title>Does a certain layer exist in map?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823449#M2926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the best way to determine if a layer exists or not? &amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone suggest a check to go through before the code below runs that will check for the layers existence? &amp;nbsp;I would think evaluating &lt;SPAN style="color: #2b91af; font-size: 9.5pt;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN style="color: black; font-size: 9.5pt;"&gt;.Active.Map.FindLayers(&lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 9.5pt;"&gt;"GISWRKS1.WORKS.VLS_Points"&lt;/SPAN&gt;&lt;SPAN style="color: black; font-size: 9.5pt;"&gt;) to&amp;nbsp;&lt;/SPAN&gt;a boolean &lt;SPAN style="font-size: 9.5pt; color: black;"&gt;would work, but I can't seem to get it to.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt; vlsLayer = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;.Active.Map.FindLayers(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #a31515;"&gt;"GISWRKS1.WORKS.VLS_Points"&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;).First() &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;BasicFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt; selection = vlsLayer.GetSelection();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;IReadOnlyList&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;long&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;gt; selectedOIDs = selection.GetObjectIDs();&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: green;"&gt;//save the selected OBJECTIDs to a list.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; color: green;"&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Aug 2017 18:02:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823449#M2926</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2017-08-21T18:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Does a certain layer exist in map?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823450#M2927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For anyone interested, this seems to work. &amp;nbsp;If you know of another way, please post it below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;IEnumerable&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;Layer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;gt; layerCheck = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;.Active.Map.GetLayersAsFlattenedList().Where(l =&amp;gt; l.Name.IndexOf(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #a31515;"&gt;"GISWRKS1.WORKS.VLS_Points"&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;StringComparison&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;.CurrentCultureIgnoreCase) &amp;gt;= 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt; count = layerCheck.OrderBy(l =&amp;gt; l).Count();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt; (count &amp;lt; 1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt; text-indent: .5in;"&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;ArcGIS.Desktop.Framework.Dialogs.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #2b91af;"&gt;MessageBox&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;.Show(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #a31515;"&gt;"Please add the VLS Layer to the map."&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: #a31515;"&gt;"Missing Layer"&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt; text-indent: .5in;"&gt;&lt;SPAN style="font-size: 9.5pt; color: blue;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; color: black;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-align: left;"&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Aug 2017 19:30:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823450#M2927</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2017-08-21T19:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Does a certain layer exist in map?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823451#M2928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These are a few ways to check for a layer:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;//Finds a layer using a URI.&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;//The Layer URI you pass in helps you search for a specific layer in a map&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; lyrFindLayer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MapView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Active&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FindLayer&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CIMPATH=map/u_s__states__generalized_.xml"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; 

&lt;SPAN class="comment token"&gt;//This returns a collection of layers of the "name" specified. You can use any Linq expression to query the collection.&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; lyrExists &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MapView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Active&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;GetLayersAsFlattenedList&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;OfType&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;FeatureLayer&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Any&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Name &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"U.S. States (Generalized)"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;//Finds layers by name and returns a read only list of Layers&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; MapView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Active&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FindLayers&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"U.S. States (Generalized)"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;FirstOrDefault&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Uma&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:47:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/does-a-certain-layer-exist-in-map/m-p/823451#M2928</guid>
      <dc:creator>UmaHarano</dc:creator>
      <dc:date>2021-12-12T09:47:16Z</dc:date>
    </item>
  </channel>
</rss>

