2

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 25, 2018 at 18:09
1
  • Do you get a line number in the error message? Dont combine paths using +, instead use os.path.join. Example: os.path.join(r'C:\arcGIS_Shared\Python', r'CenterHeatMaps.aprx') Commented Jan 25, 2018 at 20:07

1 Answer 1

3

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.