1

I am trying to render graduated symbology for dynamically called layers using arcpy in ArcGIS Pro 2.7. The first code block below adds the layers to the map, but when I try to call these layers and customize the symbology I receive errors as included below in the 2nd and 3rd code block.

Is the problem that I am not calling the layers correctly?

#List features from Results feature dataset, #Makes feature layer from features, adds feature layers to map

m = aprx.listMaps()[0]
datasets = arcpy.ListDatasets(feature_type='feature')
for ds in datasets:
    ResultList= arcpy.ListFeatureClasses("*", "ALL", ds)
    for fc in ResultList:
        OutFile = os.path.join(wkspc, str(fc))
        arcpy.MakeFeatureLayer_management(fc, fc, None, None)
        lf = arcpy.management.SaveToLayerFile(fc, OutFile)

#render graduated symbology for the layers referenced above;

Line 2: for lyr in l(): TypeError: 'layer' object is not callable

l= m.listLayers()[0]
for lyr in l():  
  if lyr.isFeatureLayer:
     sym = lyr.symbology
     if hasattr(sym, 'renderer'):
       if sym.renderer.type == "GraduatedSymbolsRenderer":
#modify graduated symbol renderer
        sym.renderer.classificationField = "Total_Deli"
        sym.renderer.breakCount = 6
        sym.renderer.minimumSymbolSize = 10
        sym.renderer.maximumSymbolSize = 25
    
        lyr.symbology = sym

Different approach--

Line 2: sym = l.symbology AttributeError: 'list' object has no attribute 'symbology'

    l = m.listLayers()[0]
    sym = l.symbology  
    if hasattr(sym,'renderer'):
        if sym.renderer.type == "GraduatedSymbolsRenderer":
            sym.renderer.classificationField = "Total_Deli"
            sym.renderer.breakCount = 6
            sym.renderer.minimumSymbolSize = 10
            sym.renderer.maximumSymbolSize = 25
    
            l.symbology = sym  
1

Problem solved.

Edited casting m.listLayers to variable l, just directly used m.listlayers (line 1). Also needed to utilize the sym.updateRenderer function to change the layer symbology. Code below.

  for lyr in m.listLayers():
      if lyr.isFeatureLayer:
          sym = lyr.symbology
          if hasattr(sym, 'renderer'):
              if sym.renderer.type == "SimpleRenderer":
                  sym.updateRenderer('GraduatedSymbolsRenderer')
                  sym.renderer.classificationField = "Total_Deli"
                  sym.renderer.breakCount = 6
                  sym.renderer.minimumSymbolSize = 1
                  sym.renderer.maximumSymbolSize = 10
    
                  lyr.symbology = sym

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.