Select to view content in your preferred language

ApplySymbologyFromLayer not working

944
4
10-24-2022 05:01 PM
Katie_Clark
MVP Regular Contributor

Hello,

I am attempting to write a map automation script for ArcGIS Pro. Taking things one step at a time, and so far the script successfully creates some layers, adds them to a specified geodatabase, and then adds them to the current map in the Pro project. I then need to apply symbology to the layers, which I am trying to do using arcpy.ApplySymbologyFromLayer_management. Here is a snippet from my code:

 

aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Primary Map Frame")[0]
m.addDataFromPath(f"{out_gdb}\BackgroundPointsFiltered_{dateTag}")
m.addDataFromPath(f"{out_gdb}\CompliancePointsFiltered_{dateTag}")
m.addDataFromPath(f"{out_gdb}\WorkLocationPointsFiltered_{dateTag}")

in_layer = m.listLayers()[2] # The background points layer that was just added to the map frame
in_symbology_layer = r"R:\gis\.....BackgroundPointsFiltered.lyrx" 
arcpy.ApplySymbologyFromLayer_management(in_layer, in_symbology_layer)

 

I've tried many other variations that I've seen from hints on stackexchange and geonet, but none have seemed to work for me. The script doesn't fail, but the symbology doesn't update.

What am I doing wrong here? Or is this somehow still related to a bug that I've seen mentioned related to this tool?

I'm using ArcGIS Pro v3.0.2

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

This bug

BUG-000116527: ApplySymbologyFromLayer in a Python script in ArcGIS.. (esri.com)

BUG-000108497: Running the Apply Layer Symbology tool as a script i.. (esri.com)

The latter has the clever solution

Close and re-open the project.

In either event, subscribe to the bugs so they get elevated and addressed since there are number of issues with this for not only vector geometry but raster symbology


... sort of retired...
0 Kudos
Katie_Clark
MVP Regular Contributor

Thanks for the response, Dan. I subscribed to both of those bugs.

However, I tried the workaround of closing and reopening the project and the symbology still hadn't been applied to the layer. Any ideas of what else could be causing it?

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
DanPatterson
MVP Esteemed Contributor

Not sure, but checking to see if it does it manually through the interface would be my first check.  

Often when "one would expect" the symbology to be updated for the same geometry type, I have often been surprised by expectations


... sort of retired...
0 Kudos
DonMorrison1
Frequent Contributor

I have some old code where ApplySymbologyFromLayer did work (not used anymore so I can't test it). You can see the the layer was created differently, I used a .lyr file,  and I specify the layer title as the first parameter. 

arcpy.MakeFeatureLayer_management(in_features, layer_title, where_clause)
symbology_fn = r"xxxxxx.lyr"
arcpy.ApplySymbologyFromLayer_management (layer_title, symbology_fn)

 

0 Kudos