I recently switched from Desktop to Pro and totally at a loss of figuring out how to make this very simple script work in ArcPro. Note that it runs and says success but the symbology does not change.
import arcpy
in_fc = arcpy.GetParameterAsText(0)
in_lyrx = arcpy.GetParameterAsText(1)
arcpy.management.ApplySymbologyFromLayer(in_fc,in_lyrx)
Darren / Joshua,
Interesting test you suggested so I simplified the script and it still runs "successfully" as a script but the symbology doesn't change. When I run ApplySymbology from the python window with the exact same parameters, it runs successfully AND the symbology does change. So, It's a problem with running it from a Script but I still don't know why.
SCRIPT
After Script is Run (no change in symbology)
After Same Parameters are used in ApplySymbology function run from Python Window
on a lark... in the map that symbology didn't change... did you toggle it on and off?
Yea. I just re-ran it, toggled it, closed the map and reopened and no change in the symbology. Was worth checking but no dice.
The answer to your question may be buried in the Setting output symbology in scripts documentation. I haven't had time to read it and fully digest that page yet.
I'm encountering exactly the same problem. At an absolute loss just like yourself. The apply symbology geoprocessing tool works fine but I can't get this function working in python at all.
Thomas see my reply to this question I posted today. I hope it helps.
My experience with arcpy.ApplySymbologyFromLayer_management was that the script would complete with no error. The layer would lock itself out in TOC while the script was running as if the symbology was being set, but when the arcpy.ApplySymbologyFromLayer_management completed the layer's symbols, labeling, popup, etc. didn't actual update.
For anyone still struggling with this, "Refreshing" the layer's connection properties after applying the layer file did the trick. I think it is a bug (I was hopeful 2.1 would fix it), but non the less the following worked for me.
# Tested with ArcPro 2.0+ # ApplySymbologyFromLayer_management Bug Work Around import arcpy # Set the workspace if desired # arcpy.env.workspace = 'C:\data' # Set layer to apply symbology to inputLayer = "FDT_02171592" # in the current workspace # Set layer that output symbology will be based on symbologyLayer = 'N:\ArcGIS - Materials\Project Template\Layer Files\FDT_v1_5.lyrx' # Symbolize the input by Test_Status field symbologyFields = [["VALUE_FIELD", "Test_Status", "Test_Status"]] # Apply the symbology from the symbology layer to the input layer arcpy.ApplySymbologyFromLayer_management(inputLayer, symbologyLayer, symbologyFields) # It would appear that the layer properties (sym, labeling, etc.) are not being applied from the layer file # when in fact they are. The bug seems to revolve around the layer display cache. Apply sym from layer via arcpy, no # change appears, but if you then go into the layer's properties and clear the cache and change the cache setting # to do not cache the sym from the layer file all of the sudden appear. Many of the layer properties are not exposed # via arcpy, however, we can "artificially" update the layer's connection properties by setting the new connection # info equal to the current connection info. By doing this we are essentially "refreshing" the connection. This # produces the desired effect with applySymbologyFromLayer through arcpy. aprx = arcpy.mp.ArcGISProject("CURRENT") # Reference the open project myMap = aprx.listMaps()[0] # Get the map that contains the input layer myLayers = myMap.listLayers() # either get the input layer and refresh or get a list of layers and iterate and refresh for layer in myLayers: if layer.name == inputLayer: # "Refresh" the layer connection properties by setting the new connection = current connection layer.updateConnectionProperties(inputLayer, inputLayer)