When running this Code:

import arcpy 
from arcpy import env
import os

#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r"G:\\PythonCode\\mxd_test.mxd")
env.workspace = r"G:\\LoopTest.gdb"
#output file folder
outPath = r"G:\Mxd_MapAutomation\\Test4\\"

FCs = arcpy.ListFeatureClasses()

# loop through all Featurecalsses in env.workspace
for FCLASS in FCs:

    #Skip all Text. OID and Geometry Fields - unfortunately WID, Shape Area etv is still included
    AllFields = [f.name for f in arcpy.ListFields(FCLASS)]
    LeaveOutField = [f.name for f in arcpy.ListFields(FCLASS,field_type='String')]
    LeaveOutField.extend([f.name for f in arcpy.ListFields(FCLASS,field_type='Geometry')])
    LeaveOutField.extend([f.name for f in arcpy.ListFields(FCLASS,field_type='OID')])
    attrlist = [x for x in AllFields if x not in LeaveOutField]

    # layer which has to change the attribute field
    flayer = arcpy.mapping.ListLayers(mxd, "*")
    featurelayer = flayer[7]

    # text element that has to change (e.g. title...)
    title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "map_title")[0]
    for attr in attrlist:

        # change value field
        featurelayer.symbology.valueField = attr

        # change tilte
        title.text = attr

        # update view

        # export as jpeg
        outJPEG = os.path.join(outPath, FCLASS + "_" + attr + ".jpg")
        arcpy.mapping.ExportToJPEG(mxd, outJPEG, "PAGE_LAYOUT", 200, 200, 300, False, "24-BIT_TRUE_COLOR", 90, False)

del mxd

I get following error:

    Traceback (most recent call last):
  File "G:/DDP_loop_Code.py", line 35, in <module>
    featurelayer.symbology.valueField = attr
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 87, in _set
    return setattr(self._arc_object, attr_name, cval(val))
ValueError: hhfishing

and I have no idea why.. the code basically runs through all FC in the GDB. It does it correctly with the first FeatureClass and stops with the error in the second Feature Class. Even if I would put in other Feature Classes the Error would appear in the same way. All the fields are either float or integer and the field where the error appears is not different to any other field where the code works on..

  • 2
    Where exactly are you getting the error?
    – nagytech
    Jun 11, 2015 at 4:50
  • 1
    What's the precise error message and line number in relation to the code snippet that you have provided? Please edit it into your question.
    – PolyGeo
    Jun 11, 2015 at 5:09
  • 1
    It seems to me that your layer probably has a UniqueValuesRenderer so setting a field other than int (long/short) into the .valueField is going to cause pain.. is this correct? Without the exact error message (like @PolyGeo said) I can't be certain; the information contained in the wording is important so it needs to be a verbatim copy. The only way to get around this is to ensure that every layer has an integer symbology field... is the field you're trying to use the same name for every feature class? or is it always the -5th element like you have? Jun 11, 2015 at 5:23
  • The error that you have included is only part of what I was expecting, and unfortunately the least useful part. Can you please try running your code from an IDE like IDLE and provide us with the whole error - in particular the bit that tells us the line number of your script and what it was executing when it errored.
    – PolyGeo
    Jun 11, 2015 at 7:05
  • It is actually much more informative which has enabled me to start to answer your question, and to see if that question can start to become more focussed.
    – PolyGeo
    Jun 11, 2015 at 8:17

1 Answer 1


I ran the test code below using ArcGIS 10.3.1 for Desktop:

import arcpy
mxd = arcpy.mapping.MapDocument("C:\\temp\\temp.mxd")
featurelayer = arcpy.mapping.ListLayers(mxd, "Animals_Insects")[0]
attr = 'hhsericiculture'
featurelayer.symbology.valueField = attr
print "Works for field hhsericiculture"
attr = 'pct_ahhwinsect_raising'
featurelayer.symbology.valueField = attr
print "Gets error before getting here"

I saw the first print statement appear, as expected, but I also saw the second which means that the error you describe was not encountered on the line before.

These are my field definitions:

  • hhsericiculture

enter image description here

  • pct_ahhwinsect_raising

enter image description here

and my symbology settings for the layer:

enter image description here

I think you should double-check whether I am running an identical test to yours. If so, perhaps this is a version difference between your 10.1 and my 10.3.1.

As an afterthought I wonder whether your field has any null values in it - I know that mine does not - and it might explain why you are getting a ValueError rather than another type of error.

  • I updated my question, still couldn't figure out the error. Jun 19, 2015 at 8:08
  • I suspect that there are null values in your hhfishing field now.
    – PolyGeo
    Jun 19, 2015 at 8:39
  • there are but they need to be <null>.. is this process not possible with null-values? Jun 22, 2015 at 4:49
  • You should be able to apply a definition query to your layer to leave just those which are non null.
    – PolyGeo
    Jun 22, 2015 at 5:20
  • do I do this with if foo is None: ? or is it more a code like this? gis.stackexchange.com/questions/90736/… ? Jun 23, 2015 at 3:16

Your Answer

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

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