Attempting to use arcpy.management.ApplySymbologyFromLayer in a python script being run in a model.
Immediate Window:
aprxMap = aprx.listMaps("Layer1")[0]
lyr = aprxMap.listLayers("PointLayer")[0]
arcpy.management.ApplySymbologyFromLayer(lyr, "Q:\GIS_Data\Symbology_Layers\TypeSymbology.lyr")
After reviewing the following link, I attempted that formatting as well within the script, but still not seeing any updates to the symbology. The script runs through with no errors, but nothing changes. Works perfectly in the immediate window though.
Reference the following documentation for creating the script: https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/apply-symbology-from-layer.h...
In immediate mode, I assume you are using a python notebook or the python window inside Pro
Is the model being run from within a toolbox?
Hi Dan,
Yes, I am using the python window in ArcGIS Pro to test the code at which point it does everything as expected. The same code is then saved as a script in a toolbox. When run from the tool box the script runs with no errors, BUT the symbology is not changed.
Kristie
I don't usually update symbology, but I do know that results from a tool should be added to a display, which makes me think that there is no "update" for existing layers.
On a lark, if you toggle off the layer, then toggle it back on, does it update?
If not, check @curtvprice 's comments in
Question on Apply symbology layer for modelbuilder... - Esri Community
If he catches this he probably has some ideas
Unfortunately, toggling the layer did not cause it to update. I looked at the link you provided, and I am familiar with that method of applying symbology to the output of the tool; however, I do not believe that works in this situation as this portion of my model is actually a python script, so I do not believe I can utilize that feature here. The model runs all of the analysis tools and saves the outputs in a specified geodatabase. The python script then goes through and adds all of the output layers to their respective layouts and then is supposed to apply symbology prior to exporting all of the layouts to png.
off to Tech Support to see if it is a bug or working as expected would be my suggestion
After doing some testing I have been somewhat able to use the information in the link you provided to update symbology; however, have come across a new issue with inconsistency. To sum up the overall model, its starts with an overall data set and then makes multiple subsets of that data by the specified categories and the applies the same layer file for the symbology to each of them. When applying the symbology it only applies it correctly to maybe half of the subsets and is inconsistent in choosing which ones are properly loaded every time the tool runs. I am waiting for my administrator to allow my account access to chat with tech support.
Thank you for all of your help!
Any updates on this? I am having similar issues and also get the same results when running from the python window in ArcGIS Pro. Thanks in advance!
I contacted ESRI customer support for this issue and it resulted in them submitting a ticket for a bug. (#BUG-000129995 The Layer symbology fails to update in the Script tool if the layer is accessed through a Script tool parameter.) Still waiting on a software update to resolve the issue. In the mean time, they do have a work around posted under this bug - I have not tried it yet though as I just saw it under the bug posting.
------------------------------------------------------------------
If layer is accessed through:
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps('Map')[0]
layer = arcpy.GetParameter(0) # FeatureLayer Parameter
fld1 = arcpy.GetParameter(1) # String Parameter
fld2 = arcpy.GetParameter(2) # String Parameter
sym = layer.symbology
layer = m.listLayers(layer.name)[0]
There is no issue.
Use stand alone Python script using arcpy.mp.ArcGISProject.SaveACopy().
Thanks Kristie,
I got around it by automating my AGOL layer upload. I used the itemID of the layer I shared that had the symbology I wanted to apply. After that I automated my layer upload and used the same itemID and that updated the layer while keeping the same symbology.
I appreciate your response!