I have this script to apply the symbology from one layer to many. But when I try and run it, I get the following error: RuntimeError: Object: Error in executing tool
Here is the rest of my code:
import arcpy
# Reference current project and mapframe.
relpath = r'C:\arcGIS_Shared\Python'
p = arcpy.mp.ArcGISProject(relpath + r'\CenterHeatMaps.aprx')
m = p.listMaps('Map')[0]
# Layer file symbology to be imported.
symbology_layer = (r"C:\arcGIS_Shared\Python\Annual2017_CA_ReferenceLyrx.lyrx")
# Layer to receive imported symbology.
layers = m.listLayers("CA201*")
for lyr in layers:
#Maintain the symbology ranges
# arcpy.update_symbology('MAINTAIN')
#Apply the symbology
arcpy.ApplySymbologyFromLayer_management(layers, symbology_layer)
#print results
print(lyr.name)
count = arcpy.GetMessageCount()
print (arcpy.GetMessage(count-1))
What am I missing or doing wrong?
asked Jan 25, 2018 at 18:09
1 Answer 1
You're passing in a list of layers: layers
to the ApplySymbologyFromLayer tool.
instead, you need to pass in just the layer: lyr
for lyr in layers:
arcpy.ApplySymbologyFromLayer_management(lyr, symbology_layer)
answered Feb 12, 2018 at 14:21
lang-py
os.path.join(r'C:\arcGIS_Shared\Python', r'CenterHeatMaps.aprx')