Select to view content in your preferred language

arcpy.management,ApplySymbologyFromLayer works from immediate window, but not when running saved script

2579
13
01-27-2022 10:43 AM
KristieReece
New Contributor III

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...

 

 

13 Replies
RosemaryHatch
New Contributor III

Hi Kristie,

I am having a similar problem (Pro 3.0.2) where the apply symbology works fine running it in a Notebook, but doesn't apply when running from a script tool. Did you ever get a resolution to this? 

Thanks!

Rosemary

0 Kudos
AvinashPatel
New Contributor II

Check and apply the right parameters to update the layer symbology

AvinashPatel_0-1677164442946.png

import arcpy
import sys
def ScriptTool(param0, param1):
# Script execution code goes here
return
# This is used to execute code if the file was run but not imported
if __name__ == '__main__':
# Tool parameter accessed with GetParameter or GetParameterAsText
param0 = arcpy.GetParameterAsText(0)
param1 = arcpy.GetParameterAsText(1)

ScriptTool(param0, param1)
arcpy.management.ApplySymbologyFromLayer(param0, param1, None, "DEFAULT")

# Update derived parameter values using arcpy.SetParameter() or arcpy.SetParameterAsText()

 

0 Kudos
Ramitha
New Contributor II

When run as a script, arcpy.management.ApplySymbologyFromLayer returns a new layer but does not modify any of it's inputs. Something like this should do the job?

# Apply symbology changes to lyr, which will create a new finalLayer:
finalLayer = arcpy.management.ApplySymbologyFromLayer(lyr, "Q:\GIS_Data\Symbology_Layers\TypeSymbology.lyr")
# Remove the original lyr from aprxMap
aprxMap.removeLayer(lyr)
# Add the new layer that has the symbology applied
aprxMap.addLayer(finalLayer[0])

 

MK13
by
Occasional Contributor

This worked for me. Thank you!! I wish it was part of the documentation.

0 Kudos