ArcPy Apply Symbology from Layer not working

08-23-2018 01:12 PM
New Contributor III

When I try to import symbology via the Python command window, it appears to work, but instead, the symbology has NOT changed, and I get this message below within the Symbology pane. I actually have to remove the layer from the map entirely, and re-add it to the map in order to update the symbology at all.

18 Replies
New Contributor II

I'm experiencing the same exact issue. I'm using Arcgis Pro 2.2.4.

Using the Apply Symbology from Layer tool through the UI works fine. Through the Python window, however, no luck. After running the tool using the UI, I copied the code snippet from the geoprocessing history window. Running that code results in the behavior described above.

New Contributor II

To add to my above comment. When I run the tool from the UI, my window looks like this:


This works fine. When I copy the code snippet from the geoprocessing history, the code looks like this:

Executing this code results in the behavior described above by Daniel Matranga.

Occasional Contributor II

I'm having a similar issue. I wrote a script that downloads a file from the National Weather Service, and attempts to apply symbology from a lyrx file. I was experiencing the issue you mentioned, but after I changed the python line to ApplySymbologyFromLayer_management instead of  as the copy Python command outputs, that issue resolved. 

I'm not sure why the output from "Copy Python Command" is different from what is suggested in the docs for this command. 

The issue I am having is a bit different. The attribute table seems to be erased after I apply symbology. It's almost as if the lyrx file that I'm getting the symbology from is substituted with the orig layer. 

0 Kudos
Esri Contributor

This bug with Apply Symbology From Layer not working in Python has been fixed in the ArcGIS Pro 2.3 release. For reference you can use Esri bug BUG-000106281.

0 Kudos
Occasional Contributor II

When will the non-beta be available though?

0 Kudos
New Contributor II

BUG-000106281 about this issue is apparently fixed for Pro SDK at release 2.3,

but I still cannot apply symbology from a layer file to a layer in my map through a script tool in Pro.

I have tried both call methods:, symbology_layer)

arcpy.ApplySymbologyFromLayer_management(target_layer, symbology_layer)

And I have tried .lyr and .lyrx

I know it is a problem with Pro, because if I run the exact same script tool in ArcMap (10.3) it works properly.

Any information or suggestions?

MVP Regular Contributor

Have you also attempted to first explicitely add both the "target_layer" and "symbology_layer" to a Map in Pro using arcpy "addLayer", and then run the "arcpy.ApplySymbologyFromLayer_management" command, instead of first updating symbology, and then adding the symbolized layer to the Map?

In my experience, this seems to solve the issue with the styling not updating. After that, I simply delete the no longer needed "symbology_layer" using arcpy "removeLayer" in the Map document of Pro.

0 Kudos
New Contributor III

Hi Marco could you expand on this answer? I'm running into the same issue, where the symbology isn't updating.

If my 'target' dataset is sitting as a feature class in a fgdb, how do I use 'addLayer', i.e. what do I pass to it? I've tried using MakeFeatureLayer but it never seems to like the output from that. I've also tried grabbing an existing layer from a map, using this with addLayer (which does add the layer again), but then the ApplySymbologyFromLayer still doesn't work. This is all running from an arcpy script tool.

I'd appreciate any solutions to this!

0 Kudos
Occasional Contributor

There is a defect logged for this when used in a script tool:

BUG-000119907: The Apply Symbology From Layer tool (arcpy.ApplySymbologyFromLayer_management) does not work if used in a Python script from the toolbox in ArcGIS Pro 2.3.

Please contact Esri Support if you wish to be attached to this defect so you can track its status.