0

Is it possible to set a Symbol Template for a GraduatedSymbolsRenderer using ArcPy for ArcGIS Pro?

The reason I ask is that running the test code below gives an error of:

Traceback (most recent call last):
  File "C:\Temp\test.py", line 10, in <module>
    symTemp = sym.renderer.symbolTemplate
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 90, in _get
    return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name))
RuntimeError

To run the code I created a test project and added one layer into it which had the ne_10m_populated_places.shp from Natural Earth as its data source.

This is the test code, and it is very close to a code sample from the GraduatedSymbolsRenderer documentation:

import arcpy
aprx = arcpy.mp.ArcGISProject(
    r"C:\Temp\Projects\TestProject\TestProject.aprx")
mapx = aprx.listMaps("Map")[0]
lyr = mapx.listLayers("ne_10m_populated_places")[0]

sym = lyr.symbology
sym.updateRenderer('GraduatedSymbolsRenderer')

symTemp = sym.renderer.symbolTemplate         # Line giving error
symTemp.applySymbolFromGallery("Circle 1")
symTemp.color = {'RGB' : [38,115,0,0]}
sym.renderer.updateSymbolTemplate(symTemp)

sym.renderer.classificationField = "POP2020"
sym.renderer.breakCount = 10
sym.renderer.minimumSymbolSize = 4
sym.renderer.maximumSymbolSize = 16

lyr.symbology  = sym
aprx.save()

I ran my test using ArcGIS Pro 2.4.1 on Windows 10 Pro for Workstations.

0

The local Esri support were able to reproduce the result of my test and submitted a bug report:

BUG-000125730 - Error Setting Symbol Template for ArcGIS Pro GraduatedSymbolsRenderer from ArcPy

I cannot think of any workaround that I can use for this, and its priority is at a low enough level, that I have just subscribed to the bug, and when I am notified that a fix is available, I plan to retest.

0

The issue is that you can’t change the renderer for a point FC, it has nothing to do with the symbolTemplate as originally stated.

Even this will fail on a point FC, simple symbol renderer:

sym = lyr.symbology
sym.updateRenderer('GraduatedSymbolsRenderer')
l.symbology = sym

Workaround Add a layer file (template) that has the renderer set for the point FC, then change its data source to your correct point FC, update the classificationField to refresh the stats for the new layer and then remove the original, replaced layer.

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
lyr1 = m.listLayers('SimplePtLayer')[0]
lyrFile = arcpy.mp.LayerFile(r"C:\Temp\GraduatedColors_Point.lyrx")
lyr2 = m.addLayer(lyrFile)[0]
lyr2.updateConnectionProperties(lyr2.connectionProperties, lyr1.connectionProperties)
sym = lyr2.symbology
sym.renderer.classificationField = 'Elevation'  #resets field and stats

#Update symbol template - keep in mind lyrx could already have it.
symTemp = sym.renderer.symbolTemplate
symTemp.applySymbolFromGallery('Square 1')
sym.renderer.updateSymbolTemplate(symTemp)

#apply changes
lyr2.symbology = sym

#remove original layer
m.removeLayer(lyr1)
  • After further investigation it was discovered that the layer being set from simple symbol to graduated colors did not have appropriate attributes to support this renderer. The same occurs in the UI and an error message appears stating the issue. – Jeff Barrette Nov 12 '19 at 17:46

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.