<?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 Re: How to test if a Layer exists in a map in Model Builder in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010701#M35162</link>
    <description>&lt;P&gt;Hi Leandra,&lt;/P&gt;&lt;H3&gt;Answer Summary&lt;/H3&gt;&lt;P&gt;You can either do this by developing a custom script tool that checks the layer for you and then returns an output that you can evaluate....or by using the&amp;nbsp;&lt;STRONG&gt;Calculate Value&lt;/STRONG&gt; tool with a custom Python function and then check the output value of that tool with the&amp;nbsp;&lt;STRONG&gt;If Value Is&lt;/STRONG&gt; tool to create the split branch you had in your model above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndrewStickney1_0-1608227335385.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/2493i324D5C8574CD4524/image-size/large?v=v2&amp;amp;px=999" role="button" title="AndrewStickney1_0-1608227335385.png" alt="AndrewStickney1_0-1608227335385.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;H4&gt;Configuring the Calculate Values tool&lt;/H4&gt;&lt;P&gt;Here's how to configure the&amp;nbsp;&lt;STRONG&gt;Calculate Values&lt;/STRONG&gt;&amp;nbsp;tool.&lt;/P&gt;&lt;P&gt;Expression Field:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;CheckLayer("%Test Layer%")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the "Test layer" is referring to my layer variable in my model that I am checking for existence. You would need to change in your model to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;CheckLayer("%UGB_Layer%")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code Block field:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def CheckLayer(layer):
	try:
		import arcpy
		# current ArcGIS Pro project
		aprx = arcpy.mp.ArcGISProject("CURRENT")
		# current  open map
		map = aprx.activeMap 
		
		#check to see if the layer is listed in map
		if layer in map.listLayers(layer):
			return "PRESENT"
		else:
			return "NOTPRESENT"
	except:
		return "NOTPRESENT"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Make sure to set the Data type to &lt;STRONG&gt;String&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H4&gt;Configuring the &lt;STRONG&gt;If Value Is&lt;/STRONG&gt; tool&lt;/H4&gt;&lt;P&gt;Set the output of the Calculate Value to be the input Value to check.&lt;/P&gt;&lt;P&gt;Keep the default value for the Value Test "Is equal to at least one value"&lt;/P&gt;&lt;P&gt;Set the Comparison Type to "Case Insensitive string"&lt;/P&gt;&lt;P&gt;Values - you only need to type in&amp;nbsp;&lt;STRONG&gt;PRESENT&lt;/STRONG&gt;. This is important because you only want to test for the "True" branch condition. Any other value (i.e.&amp;nbsp;&lt;STRONG&gt;NOTPRESENT)&lt;/STRONG&gt; would trigger the false branch.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndrewStickney1_1-1608228435465.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/2495i8BF3F220A5930783/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AndrewStickney1_1-1608228435465.png" alt="AndrewStickney1_1-1608228435465.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should do what you need.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Dec 2020 18:08:37 GMT</pubDate>
    <dc:creator>AndrewStickney1</dc:creator>
    <dc:date>2020-12-17T18:08:37Z</dc:date>
    <item>
      <title>How to test if a Layer exists in a map in Model Builder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010474#M35121</link>
      <description>&lt;P&gt;I am attempting to build a model to test whether a layer exists in the current map, and if true, run the command ApplySymbologyFromLayer on that particular layer as follows:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="aaaCapture.PNG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/2448i4EEFD22152611BFD/image-size/large?v=v2&amp;amp;px=999" role="button" title="aaaCapture.PNG" alt="aaaCapture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The 'If Data Exists' doesn't seem to be the right tool to test whether a layer exists and the tool runs with an error:&lt;BR /&gt;&lt;BR /&gt;Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000735: Input Values: Value is required&lt;BR /&gt;Failed to execute (13UGBLYR).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;What would be the correct tool to use to check whether a layer exists in the current map?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 02:05:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010474#M35121</guid>
      <dc:creator>LeandraGordon</dc:creator>
      <dc:date>2020-12-17T02:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a Layer exists in a map in Model Builder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010701#M35162</link>
      <description>&lt;P&gt;Hi Leandra,&lt;/P&gt;&lt;H3&gt;Answer Summary&lt;/H3&gt;&lt;P&gt;You can either do this by developing a custom script tool that checks the layer for you and then returns an output that you can evaluate....or by using the&amp;nbsp;&lt;STRONG&gt;Calculate Value&lt;/STRONG&gt; tool with a custom Python function and then check the output value of that tool with the&amp;nbsp;&lt;STRONG&gt;If Value Is&lt;/STRONG&gt; tool to create the split branch you had in your model above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndrewStickney1_0-1608227335385.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/2493i324D5C8574CD4524/image-size/large?v=v2&amp;amp;px=999" role="button" title="AndrewStickney1_0-1608227335385.png" alt="AndrewStickney1_0-1608227335385.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;H4&gt;Configuring the Calculate Values tool&lt;/H4&gt;&lt;P&gt;Here's how to configure the&amp;nbsp;&lt;STRONG&gt;Calculate Values&lt;/STRONG&gt;&amp;nbsp;tool.&lt;/P&gt;&lt;P&gt;Expression Field:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;CheckLayer("%Test Layer%")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the "Test layer" is referring to my layer variable in my model that I am checking for existence. You would need to change in your model to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;CheckLayer("%UGB_Layer%")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code Block field:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def CheckLayer(layer):
	try:
		import arcpy
		# current ArcGIS Pro project
		aprx = arcpy.mp.ArcGISProject("CURRENT")
		# current  open map
		map = aprx.activeMap 
		
		#check to see if the layer is listed in map
		if layer in map.listLayers(layer):
			return "PRESENT"
		else:
			return "NOTPRESENT"
	except:
		return "NOTPRESENT"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Make sure to set the Data type to &lt;STRONG&gt;String&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H4&gt;Configuring the &lt;STRONG&gt;If Value Is&lt;/STRONG&gt; tool&lt;/H4&gt;&lt;P&gt;Set the output of the Calculate Value to be the input Value to check.&lt;/P&gt;&lt;P&gt;Keep the default value for the Value Test "Is equal to at least one value"&lt;/P&gt;&lt;P&gt;Set the Comparison Type to "Case Insensitive string"&lt;/P&gt;&lt;P&gt;Values - you only need to type in&amp;nbsp;&lt;STRONG&gt;PRESENT&lt;/STRONG&gt;. This is important because you only want to test for the "True" branch condition. Any other value (i.e.&amp;nbsp;&lt;STRONG&gt;NOTPRESENT)&lt;/STRONG&gt; would trigger the false branch.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndrewStickney1_1-1608228435465.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/2495i8BF3F220A5930783/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AndrewStickney1_1-1608228435465.png" alt="AndrewStickney1_1-1608228435465.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should do what you need.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 18:08:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010701#M35162</guid>
      <dc:creator>AndrewStickney1</dc:creator>
      <dc:date>2020-12-17T18:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a Layer exists in a map in Model Builder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010826#M35188</link>
      <description>&lt;P&gt;Thanks Andrew, I'll give that a go. I'm trying to get around a Python bug with Apply Symbology so it would either be run the model in the Python Script or run some Python in the Model &lt;SPAN class="lia-emoticons-autosuggestions"&gt;&lt;SPAN class="lia-emoticons-search-term"&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 00:05:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1010826#M35188</guid>
      <dc:creator>LeandraGordon</dc:creator>
      <dc:date>2020-12-18T00:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a Layer exists in a map in Model Builder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1072470#M42499</link>
      <description>&lt;P&gt;In the end I used the iterate Layers and set the wildcard to the layer name itself.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LeandraGordon_0-1624608753806.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/16955i824F699940063036/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LeandraGordon_0-1624608753806.png" alt="LeandraGordon_0-1624608753806.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slightly clumsy but it will suffice until the Apply Symbology from Layer bug is fixed in Python Toolboxes (and Jupyter Python as well!)&lt;BR /&gt;&lt;BR /&gt;&amp;lt;rant&amp;gt;As an aside it seems that anything I try and do in Python to manipulate layers (moving, showing/hiding popups, changing symbology) just doesn't work in scripts so I'm going to try to do all that in model building becuase at least it seems to do 'what it says on the box'&amp;lt;/rant&amp;gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 08:12:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-test-if-a-layer-exists-in-a-map-in-model/m-p/1072470#M42499</guid>
      <dc:creator>LeandraGordon</dc:creator>
      <dc:date>2021-06-25T08:12:45Z</dc:date>
    </item>
  </channel>
</rss>

