<?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 ApplySymbologyFromLayer works in the Python window on ArcGIS Pro, but not in a ToolBox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/applysymbologyfromlayer-works-in-the-python-window/m-p/234516#M18186</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having this issue for months now, I am keeping up with the topics about it here, but no solution yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ApplySymbologyFromLayer does not work in a Python Toolbox. It does work on the Python window, but in a toolbox it does not show any result. No error, no warnings, just no effect at all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Python toolbox code is decent sized, it has a number of tools and none of them have any issue, does a lot of different tasks, but for some reason, it can't Apply Symbology From Layer. When the line runs, I can see the layer being locked for a while, and then the code complete without any results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is one workround, which is constantly suggested here, and I was using successfully:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;new_lyr_file = arcpy.mp.LayerFile(symbology_layer)
new_lyr = new_lyr_file.listLayers()[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
old_lyr = aprxMap.listLayers(inputlayer)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
old_lyr_name = old_lyr.name
new_lyr.updateConnectionProperties(new_lyr.connectionProperties&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;old_lyr.connectionProperties)
new_lyr.name = old_lyr_name
new_lyr_file.save()
aprxMap.insertLayer(old_lyr&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;new_lyr_file)
aprxMap.removeLayer(old_lyr)&lt;/PRE&gt;&lt;P&gt;Until i noticed that it screws up the URL in the Data Source. It brings some issues when trying to upload the Map to AGOL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The funny part is that both&amp;nbsp;&lt;/P&gt;&lt;P&gt;- arcpy.management.ApplySymbologyFromLayer(Input, Symbol)&lt;/P&gt;&lt;P&gt;and&amp;nbsp;&lt;/P&gt;&lt;P&gt;- arcpy.management.ApplySymbologyFromLayer(&lt;SPAN&gt;Input, Symbol&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;lines of code works perfectly when using the Python Windom on ArcGIS Pro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas why the code would run in the Python Window but not on the Toolbox?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:50:47 GMT</pubDate>
    <dc:creator>Gustavo_Souza</dc:creator>
    <dc:date>2021-12-11T11:50:47Z</dc:date>
    <item>
      <title>ApplySymbologyFromLayer works in the Python window on ArcGIS Pro, but not in a ToolBox</title>
      <link>https://community.esri.com/t5/python-questions/applysymbologyfromlayer-works-in-the-python-window/m-p/234516#M18186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having this issue for months now, I am keeping up with the topics about it here, but no solution yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ApplySymbologyFromLayer does not work in a Python Toolbox. It does work on the Python window, but in a toolbox it does not show any result. No error, no warnings, just no effect at all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Python toolbox code is decent sized, it has a number of tools and none of them have any issue, does a lot of different tasks, but for some reason, it can't Apply Symbology From Layer. When the line runs, I can see the layer being locked for a while, and then the code complete without any results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is one workround, which is constantly suggested here, and I was using successfully:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;new_lyr_file = arcpy.mp.LayerFile(symbology_layer)
new_lyr = new_lyr_file.listLayers()[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
old_lyr = aprxMap.listLayers(inputlayer)[&lt;SPAN style="color: #6897bb;"&gt;0&lt;/SPAN&gt;]
old_lyr_name = old_lyr.name
new_lyr.updateConnectionProperties(new_lyr.connectionProperties&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;old_lyr.connectionProperties)
new_lyr.name = old_lyr_name
new_lyr_file.save()
aprxMap.insertLayer(old_lyr&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;new_lyr_file)
aprxMap.removeLayer(old_lyr)&lt;/PRE&gt;&lt;P&gt;Until i noticed that it screws up the URL in the Data Source. It brings some issues when trying to upload the Map to AGOL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The funny part is that both&amp;nbsp;&lt;/P&gt;&lt;P&gt;- arcpy.management.ApplySymbologyFromLayer(Input, Symbol)&lt;/P&gt;&lt;P&gt;and&amp;nbsp;&lt;/P&gt;&lt;P&gt;- arcpy.management.ApplySymbologyFromLayer(&lt;SPAN&gt;Input, Symbol&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;lines of code works perfectly when using the Python Windom on ArcGIS Pro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas why the code would run in the Python Window but not on the Toolbox?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:50:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/applysymbologyfromlayer-works-in-the-python-window/m-p/234516#M18186</guid>
      <dc:creator>Gustavo_Souza</dc:creator>
      <dc:date>2021-12-11T11:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: ApplySymbologyFromLayer works in the Python window on ArcGIS Pro, but not in a ToolBox</title>
      <link>https://community.esri.com/t5/python-questions/applysymbologyfromlayer-works-in-the-python-window/m-p/234517#M18187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've never used &lt;SPAN style="background-color: #ffffff;"&gt;ApplySymbologyFromLayer in a toolbox so can't comment on the issue&lt;/SPAN&gt;, but what I do that works is set the symbology property of output layer &lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/classes/parameter.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;parameters&lt;/A&gt;, and the symbology is automagically applied when the output parameter is set at the end of my execute method:&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="keyword token"&gt;class&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;Tool&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;object&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;getParameterInfo&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;self&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        params &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
        params&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Parameter&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;
            displayName&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Output Raster Layer"&lt;/SPAN&gt;&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;"out_raster_lyr"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
            datatype&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"GPRasterLayer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
            parameterType&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Derived"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
            direction&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Output"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

        params&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;symbology &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'path\to\symbology.lyrx'&lt;/SPAN&gt;

        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; params
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
    &lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;execute&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;self&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; parameters&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; messages&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; do_something_and_return_a_layer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
            arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SetParameter&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; layer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# Layer gets added to the map with symbology applied without me manually applying it.&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;/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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:50:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/applysymbologyfromlayer-works-in-the-python-window/m-p/234517#M18187</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T11:50:50Z</dc:date>
    </item>
  </channel>
</rss>

