I have a python script tool that outputs points and polygons. I want to symbolize them based on a field but I'm having a hard time doing that in my code rather than manually. When I run ApplySymbologyFromLayer in the python window, the symbology applies just fine. However, when I try to do something similar at the end of my script tool, I get no errors but the symbology is unchanged. What am I missing to make this work?
Here is the code for adding the polygons. It is essentially the same for the points. I got some advice from ChatGPT while looking for a solution so I'm open to anything that needs to be remedied from that too.
polygonLayerTemplate = r"J:\User\Coding\PolygonsTemplate.lyrx"
polygonLayerName = "Polygons"
for lyr in activeMap.listLayers():
if lyr.name == polygonLayerName:
activeMap.removeLayer(lyr) # remove old version to avoid duplicates
polygonLayer = activeMap.addDataFromPath(polygonsFeatureClass)
Layer = activeMap.listLayers(polygonLayerName)[0]
arcpy.management.ApplySymbologyFromLayer(
in_layer=Layer,
in_symbology_layer=polygonLayerTemplate,
symbology_fields="VALUE_FIELD Name Name",
update_symbology="UPDATE"
)