Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Value Error with Float/Integer/double Fields in Python?

$
0
0

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
        arcpy.RefreshActiveView()
        arcpy.RefreshTOC()

        # 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)ArcGISDesktop10.1arcpyarcpyarcobjects_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..


Viewing all articles
Browse latest Browse all 767

Trending Articles