<?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: Cannot Apply Symbology From Layer Using Python Script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1306924#M68122</link>
    <description>&lt;P&gt;I know this is a little old, but I haven't found a solution mentioned online. It's quite an easy solution, but it is not well documented, if it is at all. I had to piece this together from reading different things. It actually does not even involve using the ApplySymbologyFromLayer method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the options given in &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1125"&gt;@DrewFlater&lt;/a&gt;&amp;nbsp;response and also use an output name generated in the script. The solution:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In your script tool properties, set a parameter and give it the "Derived" type to make it a derived output parameter. I got to this from the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/apply-symbology-from-layer.htm#GUID-E53C37E4-D077-48F9-B0F0-B7DA5C7D158F" target="_blank" rel="noopener"&gt;documentation on ApplySymbologyFromLayer&lt;/A&gt;, directly above the Parameters list.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Set the Symbology in that Derived Output parameter to your layer file.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Now in the script, &lt;A href="https://pro.arcgis.com/en/pro-app/2.9/arcpy/functions/setparameterastext.htm" target="_self"&gt;you will use SetParameterAsText()&lt;/A&gt; to apply your generated output (path to data, layer, etc) to the Derived Output parameter. When you do this, it will apply the symbology that you set on that parameter. See the code below for how I am using it.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# APPLIED AFTER MAKE FEATURE LAYER
fl = arcpy.management.MakeFeatureLayer(parcels,prop_name,tmap_exp)    
# using SetParameterAsText... first argument is index of your script tool's parameters, and second arg is the feature layer I generated.
arcpy.SetParameterAsText(6,fl)

# APPLIED TO A SHAPEFILE
arcpy.env.workspace = filepath
formatted_name = prop_name.replace(" ","_")
shp = arcpy.management.CopyFeatures(fl,"{}.shp".format(formatted_name))
arcpy.SetParameterAsText(6,shp)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2023 13:50:01 GMT</pubDate>
    <dc:creator>TanGnar</dc:creator>
    <dc:date>2023-07-10T13:50:01Z</dc:date>
    <item>
      <title>Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16036#M1242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am struggling to apply symbology from an existing layer file to an output from a script tool. The below snippet is from a larger script tool that takes a DEM, clips it to the Map View, smooths it using Focal Statistics, creates a feature class of contours in an existing geodatabase, and then adds an index field. The contour feature class is automatically added to the map (seemingly regardless of my use of env.addOutputsToMap).&amp;nbsp;Seems like the use of either "Add Field" or "Calculate Field" does this, which is fine, I want it there anyway.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;out_gdb &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"F:\ContourTest\ContourTest.gdb"&lt;/SPAN&gt;
cont_file &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; fr&lt;SPAN class="string token"&gt;"{out_gdb}\Contours_20"&lt;/SPAN&gt;

current_project &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
current_map &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_project&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listMaps&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="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
current_map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;addDataFromPath&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fr&lt;SPAN class="string token"&gt;"{cont_file}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

cont_layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Contour*"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&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;
symbology &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"F:\ContourTest\Contour_Index.lyrx"&lt;/SPAN&gt;

arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;management&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ApplySymbologyFromLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_layer&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;cont_layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    in_symbology_layer&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;symbology&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    symbology_fields&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"VALUE_FIELD Index_Contour Index_Contour"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    update_symbology&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"MAINTAIN"&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;/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;The above code is the last bit of the larger script. The whole thing, including this bit, runs without exceptions, but the symbology does not apply as expected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, if I then take this bit of code and paste it exactly into the Python Window and run it,&amp;nbsp;another copy of the contour feature class is added to the TOC, and the correct symbology is applied. Works perfectly. If I then remove both, the symbolized contours and the unsymbolized contours, and run the code above in the Python Window &lt;EM&gt;again&lt;/EM&gt;, just a symbolized version is added (or an unsymbolized version is added, and then the symbology is applied, either way). Again, works perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried using versions of MakeFeatureLayer, addLayer, all kinds of things--I am likely getting tripped up over the colloquial use of the term "layer," vs. the technical meaning of layer, layer file, layer object in code vs path to layer, etc. etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy to paste the entire script if that is helpful, just didn't want to clutter the question. This a script tool in a regular toolbox (.tbx) with parameters and some basic validation set up within Pro. The validation pertains to whether a contour index field should be created, checking for integer inputs, etc., so I don't think it should interfere here, but who knows. I am running ArcGIS Pro 2.5.0--it tells me that this is the current version.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:38:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16036#M1242</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2021-12-10T20:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16037#M1243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You do not need to use arcpy mp or ApplySymbology to symbolize an output dataset of a script tool.&lt;/P&gt;&lt;P&gt;There are three approaches:&lt;/P&gt;&lt;P&gt;1. Open the script tool properties, go to the Parameters page, find the output feature class parameter, scroll right to the Symbology column&amp;nbsp; click in the cell and then browse to your layer file. This is the easiest for always symbolizing the output the same way.&lt;/P&gt;&lt;P&gt;2. If you need to symbolize differently depending on the output shape type or some other factors you may want to write code to symbolize the output. You have access to a parameter's same Symbology property set through the UI above available in tool validation. See here:&amp;nbsp;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/setting-output-symbology-in-scripts.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/setting-output-symbology-in-scripts.htm"&gt;Setting output symbology in scripts—Geoprocessing and Python | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. There is a new arcpy function, arcpy.SetParameterSymbology also exactly for this purpose. This allows you to keep the Symbology logic in your source code instead of validation or the tool properties.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arcpy mp is for mapping workflow automation not GP output symbolization. These other methods give you a ton of options for performing the latter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2020 05:32:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16037#M1243</guid>
      <dc:creator>DrewFlater</dc:creator>
      <dc:date>2020-04-07T05:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16038#M1244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Drew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the helpful response, it appears I was approaching the problem from the wrong direction. Your last line in particular about the intended purpose of arcpy mp clears things up for me. Sounds like one of that above options will do exactly what I need.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2020 14:10:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16038#M1244</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2020-04-07T14:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16039#M1245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For Python Toolboxes: &lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/defining-parameters-in-a-python-toolbox.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/defining-parameters-in-a-python-toolbox.htm"&gt;Defining parameters in a Python toolbox—Geoprocessing and Python | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which helps as a workaround for this (&lt;SPAN style="font: 300 15px/2.32rem 'Avenir Next W01','Avenir Next W00','Avenir Next',Avenir,'Helvetica Neue',Helvetica,Arial,sans-serif; text-align: left; color: #007ac2; text-transform: none; text-indent: 0px; letter-spacing: normal; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;"&gt;Bug BUG-000119907&lt;/SPAN&gt;) (I hope!)&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2020 04:51:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16039#M1245</guid>
      <dc:creator>LeandraGordon</dc:creator>
      <dc:date>2020-07-02T04:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16040#M1246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I still haven't been able to figure this out. All of the above solutions seem to hinge on the output feature class being defined as a tool parameter, which is not applicable in my case. The UI takes inputs and an output location--the name of the output is generated within the script, not provided by the user. The below is the same as my first post (I believe), just cleaned up a bit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P&gt;current_project = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;map = current_project.listMaps()[0]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cont_file = r"FULLPATH\Contours_2"&lt;/P&gt;&lt;P&gt;cont_layer = map.addDataFromPath(cont_file)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cont_symbol = r"&lt;SPAN style="background-color: #f6f6f6;"&gt;FULLPATH&lt;/SPAN&gt;\Index_Contour_Symbology.lyrx"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.management.ApplySymbologyFromLayer(cont_layer, cont_symbol)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The above is the final function in my python script. It adds the layer, but it does not apply the symbology. When the exact same&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;block&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is run from the python window, it works as expected--it adds the existing feature class as a layer, and applies the symbology from the predefined .lyrx file. For&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;clarity, FULLPATH in the snippet above is replaced with the actual path in the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's not clear to me why this is considered "GP output symbolization" and not "mapping workflow automation." If this is not an applicable use case, then when would someone opt to use ApplySymbologyFromLayer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2020 19:18:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16040#M1246</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2020-07-05T19:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16041#M1247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If this is just a bug, that's fine, I'll obviously have to figure out a workaround. I'm still trying to figure out if that is in fact the case, or if I'm improperly using these functions. Thanks for the link.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2020 19:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/16041#M1247</guid>
      <dc:creator>VinceE</dc:creator>
      <dc:date>2020-07-05T19:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1006802#M59210</link>
      <description>&lt;P&gt;I don't consider this to be a solution as it doesn't work for mapping workflow automation which is still bugged. In the version of Pro I'm using now (2.6.1),&amp;nbsp;&lt;SPAN&gt;arcpy.management.ApplySymbologyFromLayer() &lt;EM&gt;does&lt;/EM&gt; work for Maps, but not for Scenes and not when using the 'Current' for either maps OR scenes (i.e. only works when referencing an ArcPro project that is not open in the current session).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 21:32:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1006802#M59210</guid>
      <dc:creator>GeoNZ</dc:creator>
      <dc:date>2020-12-03T21:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1222366#M65866</link>
      <description>&lt;P&gt;It has been a while since this thread and similar ones have been posted, and I have not seen a straightforwad workaround being shared out in the wild yet, so here's my "if its works, it's not stupid" solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# apply symbology from a lyrx file so that the lines are red and visible for user selection
# to note: symbology does not get updated for layers already loaded, 
# but will be applied subsequently to layers created from the layer with applied symbology using arcpy.analysis.Select()
orig_lyr = current_map.addDataFromPath(os.path.join(arcpy.env.workspace,"orig_lyr"))
arcpy.management.ApplySymbologyFromLayer(orig_lyr, os.path.join(os.path.dirname(arcpy.env.workspace), "layerfile.lyrx"))
new_lyr = os.path.join(arcpy.env.workspace,"new_lyr")
arcpy.analysis.Select(orig_lyr,
                      new_lyr,
                      "")
current_map.addDataFromPath(new_lyr)
# delete the original layer
arcpy.management.Delete(current_map.listLayers()[1])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this helps someone, especially since this bug has been marked as "Will not be addressed" by Esri.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 16:32:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1222366#M65866</guid>
      <dc:creator>MattGKL</dc:creator>
      <dc:date>2023-02-23T16:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1260943#M66923</link>
      <description>&lt;P&gt;I can't even seem to get this to work. It's madness as to why this isn't possible. I have a layer that I create in a custom script that isn't a parameter and I can't do something simple like apply symbology. Grrr...&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 16:01:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1260943#M66923</guid>
      <dc:creator>MattHowe</dc:creator>
      <dc:date>2023-02-23T16:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1260968#M66924</link>
      <description>&lt;P&gt;You might want to try creating both feature classes in a local gdb since that is what I was working with. Otherwise, my go-to now is to adjust the layer CIM directly like here&amp;nbsp;&lt;A href="https://gis.stackexchange.com/questions/338301/what-is-arcpy-cim" target="_blank"&gt;https://gis.stackexchange.com/questions/338301/what-is-arcpy-cim&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 16:32:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1260968#M66924</guid>
      <dc:creator>MattGKL</dc:creator>
      <dc:date>2023-02-23T16:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1306924#M68122</link>
      <description>&lt;P&gt;I know this is a little old, but I haven't found a solution mentioned online. It's quite an easy solution, but it is not well documented, if it is at all. I had to piece this together from reading different things. It actually does not even involve using the ApplySymbologyFromLayer method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the options given in &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1125"&gt;@DrewFlater&lt;/a&gt;&amp;nbsp;response and also use an output name generated in the script. The solution:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In your script tool properties, set a parameter and give it the "Derived" type to make it a derived output parameter. I got to this from the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/apply-symbology-from-layer.htm#GUID-E53C37E4-D077-48F9-B0F0-B7DA5C7D158F" target="_blank" rel="noopener"&gt;documentation on ApplySymbologyFromLayer&lt;/A&gt;, directly above the Parameters list.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Set the Symbology in that Derived Output parameter to your layer file.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Now in the script, &lt;A href="https://pro.arcgis.com/en/pro-app/2.9/arcpy/functions/setparameterastext.htm" target="_self"&gt;you will use SetParameterAsText()&lt;/A&gt; to apply your generated output (path to data, layer, etc) to the Derived Output parameter. When you do this, it will apply the symbology that you set on that parameter. See the code below for how I am using it.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# APPLIED AFTER MAKE FEATURE LAYER
fl = arcpy.management.MakeFeatureLayer(parcels,prop_name,tmap_exp)    
# using SetParameterAsText... first argument is index of your script tool's parameters, and second arg is the feature layer I generated.
arcpy.SetParameterAsText(6,fl)

# APPLIED TO A SHAPEFILE
arcpy.env.workspace = filepath
formatted_name = prop_name.replace(" ","_")
shp = arcpy.management.CopyFeatures(fl,"{}.shp".format(formatted_name))
arcpy.SetParameterAsText(6,shp)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 13:50:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1306924#M68122</guid>
      <dc:creator>TanGnar</dc:creator>
      <dc:date>2023-07-10T13:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1356916#M69332</link>
      <description>&lt;P&gt;I haven't spent a lot of time working with python toolboxes in my career (no real need for them), but recently I've had to adapt what was meant to be a standalone script into a toolbox, after discovering a bug that affects CIM (v2) FeatureLayer objects that are accessed outside of an ArcGIS Pro application.&lt;BR /&gt;&lt;BR /&gt;My tool is designed to be run on an .aprx that contains small scale transportation maps (and associated layouts) with inset areas marked on them, alongside separate large scale maps (and associated layouts) covering the inset areas. The idea is to take each polyline layer in the small scale map and break it into two layers. Layer one retains the existing symbology, but is masked inside the bounds of the inset areas. Layer two is a copy of layer one with a definition query applied (limiting it to features that intersect the inset area), no layer mask, and reduced line weights for less visual clutter.&lt;BR /&gt;&lt;BR /&gt;My workflow in the standalone script went something like this:&lt;/P&gt;&lt;PRE&gt;#1 Make the new layer, add it to the map, and move it to the correct location&lt;BR /&gt;result = arcpy.management.MakeFeatureLayer(old_layer&lt;SPAN&gt;, &lt;/SPAN&gt;new_name)&lt;BR /&gt;pro_map.addLayer(result.getOutput(&lt;SPAN&gt;0&lt;/SPAN&gt;))&lt;BR /&gt;new_inset_layer = pro_map.listLayers(new_name)[&lt;SPAN&gt;0&lt;/SPAN&gt;]&lt;BR /&gt;pro_map.moveLayer(old_layer&lt;SPAN&gt;, &lt;/SPAN&gt;new_inset_layer&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"AFTER"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;#2 Apply the Unique Values renderer to the new layer&lt;BR /&gt;arcpy.management.ApplySymbologyFromLayer(new_inset_layer&lt;SPAN&gt;, &lt;/SPAN&gt;old_layer)&lt;/PRE&gt;&lt;P&gt;At this point, we need to bring in the CIM. ApplySymbologyFromLayer sets the new layer's renderer without issue, but it defaults to using the literal values from the attribute fields as labels for the symbol classes. That's no good; this is a Unique Value renderer with multiple fields and grouped values. We don't want a label that reads:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Unpaved Road, SR; Unpaved Road, 4; Unpaved Road, 5; Unpaved Road, NA&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;we just want it to say &lt;EM&gt;Unpaved Road&lt;/EM&gt;. But we can pull those settings over from the old layer, too, using the CIM:&lt;/P&gt;&lt;PRE&gt;#2A Copy labels&lt;BR /&gt;inset_cim = new_inset_layer.getDefinition(&lt;SPAN&gt;'V2'&lt;/SPAN&gt;)&lt;BR /&gt;inset_cim.renderer.groups[&lt;SPAN&gt;0&lt;/SPAN&gt;].classes = old_layer.getDefinition(&lt;SPAN&gt;'V2'&lt;/SPAN&gt;).renderer.groups[&lt;SPAN&gt;0&lt;/SPAN&gt;].classes&lt;/PRE&gt;&lt;P&gt;From there, it's a relatively straightforward process of looking up the different symbol classes in a symbol dictionary that specifies the updated line weights and colors. (I could see how setting up a .lyrx template and retrieving the desired symbology from there might be easier than using a dictionary, but I was having fun learning the ins and outs of the CIM)&lt;/P&gt;&lt;P&gt;So I've got a solution, but now I'm wondering: how does the derived output parameter(s?) even begin to fit into this picture? As already noted, there isn't a ton of documentation out there (maybe even less than there is for the CIM!) and this thread is one of the few links that come up when I search for help.&lt;/P&gt;&lt;P&gt;(P.S. I would agree that this issue has not really been 'solved' in a meaningful way. I have no problem with Esri saying "We don't consider this a bug and we don't plan to fix it," but then they should at least provide with some clear, detailed examples of how the derived parameters workaround is intended to work.)&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 16:50:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1356916#M69332</guid>
      <dc:creator>AndrewBryson1</dc:creator>
      <dc:date>2023-12-05T16:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1380266#M69820</link>
      <description>&lt;P&gt;Hey there! I recently faced a similar problem. ApplySymbologyFromLayer function was not working in python notepad. I'm not sure if the bug hasn't been resolved by ESRI yet or if it's a problem with my software version (3.1). Ultimately, I managed to work around the problem in the following way:&lt;BR /&gt;1. I created a style (my_style.stylx file), where I wrote down what the feature should looklike depending on the attribute value - the attribute value is the name of the style icon.&lt;BR /&gt;2. Since my attributes were numeric, and in order to match them to the syle they must be strings, I wrote a loop in Python to give the new column (new_column) a string value depending on the numerical values.&lt;BR /&gt;3. I used the function arcpy.management.MatchLayerSymbologyToAStyle(my_layer, f"$feature.new_column", r"path_to_style\my_style.stylx")&lt;/P&gt;&lt;P&gt;The function "MatchLayerSymbologyToAStyle) works in python just fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 13:46:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1380266#M69820</guid>
      <dc:creator>MPrzY</dc:creator>
      <dc:date>2024-02-09T13:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515007#M71205</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1134"&gt;@JeffBarrette&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1135"&gt;@JeffMoulds&lt;/a&gt;&amp;nbsp;any thoughts on this thread? ApplySymbologyFromLayer is extremely buggy. I am able to get it to work in one map frame but not in a second non-active map frame within my python script. Could this be a case where the map has to be activated for the script to be able to access the layers within that map?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 15:33:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515007#M71205</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-05T15:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515038#M71206</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/668647"&gt;@MK13&lt;/a&gt;&amp;nbsp;for bringing this to my attention.&amp;nbsp; This is something we are looking into and need to coordinate with the core GP/arcpy team.&amp;nbsp; Here is a brief explanation and a couple of possible work-arounds.&lt;/P&gt;&lt;P&gt;ApplySymbologyFromLayer is a core GP/arcpy method.&amp;nbsp; It runs on the GP thread which includes includes GP dialogs, models, and script tools.&amp;nbsp; The GP thread provides isolation so the application (main thread) can continue to run.&amp;nbsp; Arcpy.mp was designed to work with the application objects and also runs on the main thread.&amp;nbsp; When using a script tool, its important to hook the results back to the main thread and this can be done using the technique mentioned by&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/320057"&gt;@TanGnar&lt;/a&gt;&amp;nbsp;above.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;p = arcpy.mp.ArcGISProject('current')&lt;/P&gt;&lt;P&gt;relpath = p.homeFolder&lt;/P&gt;&lt;P&gt;l&lt;STRONG&gt;yr = arcpy.GetParameter(0)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if lyr.name == ‘GreatLakes’:&lt;/P&gt;&lt;P&gt;&amp;nbsp; lyrx = os.path.join(relpath, 'GreatLakes.lyrx’)&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.management.ApplySymbologyFromLayer(lyr, lyrx)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.SetParameter(1, lyr)&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeffBarrette_0-1722874381956.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/111614i0A11E31F13AC5901/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JeffBarrette_0-1722874381956.png" alt="JeffBarrette_0-1722874381956.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another alternative is to use an all arcpy.mp solution where you "copy" the symbology using this technique.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;p = arcpy.mp.ArcGISProject('current')&lt;/P&gt;&lt;P&gt;relpath = p.homeFolder&lt;/P&gt;&lt;P&gt;for lyr in p.listMaps(‘Map’).listLayers():&lt;/P&gt;&lt;P&gt;&amp;nbsp; if lyr.name == ‘GreatLakes’:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; lyrx = os.path.join(relpath, 'GreatLakes.lyrx’)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; lyrx_lyr = lyrx.listLayers(‘GreatLakes’)[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; lyr.symbology = lyrx_lyr.symbology&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And at Pro 3.4 we hope to introduce a new (feature) Layer.pasteProperties(source_layer, properties) method that allows you copy existing layer properties from a source layer where it defaults to all default properties OR you can specify keywords such as symbology, or definition queries, field aliases, or pop-ups, etc,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeff - Layout and arcpy.mp teams&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 16:13:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515038#M71206</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2024-08-05T16:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515061#M71207</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1134"&gt;@JeffBarrette&lt;/a&gt;&amp;nbsp;updating the symbology using&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;lyr.symbology = lyrx_lyr.symbology as in your code above brings in the symbols but doesn't bring in the label classes from the original layer file. I have 2 label classes defined in the layer file but I see only one label class in the layer whose symbology has been updated and the label class' symbology was not maintained as it was in the layer file. Is that a setting that has to be set?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 17:13:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515061#M71207</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-05T17:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Apply Symbology From Layer Using Python Script</title>
      <link>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515196#M71210</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/668647"&gt;@MK13&lt;/a&gt;&amp;nbsp;Again, this is just a work around but have you tried something like ...&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;import os&lt;BR /&gt;p = arcpy.mp.ArcGISProject('current')&lt;BR /&gt;relpath = p.homeFolder&lt;BR /&gt;m = p.listMaps('Map')[0]&lt;BR /&gt;for l in m.listLayers():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if l.name == 'GreatLakes':&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lyr1 = arcpy.mp.LayerFile(os.path.join(relpath, 'GreatLakes.lyrx')).listLayers('GreatLakes')[0]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l.symbology = lyr1.symbology&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #Also copy label classes&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l_cim = l.getDefinition('V3')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lyr1_cim = lyr1.getDefinition('V3')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l_cim.labelClasses = lyr1_cim.labelClasses&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l.setDefinition(l_cim)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l.showLabels = True #Just in case they are not visible&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Jeff&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 21:53:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-apply-symbology-from-layer-using-python/m-p/1515196#M71210</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2024-08-05T21:53:33Z</dc:date>
    </item>
  </channel>
</rss>

