I'm attempting run a calculate field for a feature layer that I'm creating in this tutorial. I can't seem to set it up to run though. ERROR 999999: Error executing function. Failed to execute (CalculateField)... I want the expression to run and populate the new field in the feature layer,fc.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Import the mod
import arcpy
from arcpy import env
try:
# Set up the environment
env.workspace = \
r"E:\GISTutorial_for_PyScripting\GISTPython\Data\FireDepartment.gdb"
env.overwriteOutput = True
# Create a list of all the box zone feature classes
fcBoxZones = arcpy.ListFeatureClasses('FireBoxMap*')
# fcBoxZones = arcpy.ListFeatureClasses("FireBoxMap_14")
# Start a for statment to iterate through the files
for fc in fcBoxZones:
# Get the first file - it's stored in fc
print fc
break # If you want the first otherwise it's the last
# Add field to hold the results
arcpy.AddField_management(fc, 'LaneMiles', 'LONG')
# Select the street lanes
path = r"E:\GISTutorial_for_PyScripting\GISTPython\Data\City of Oleander.gdb\Street_Centerlines"
arcpy.MakeFeatureLayer_management(path, 'Lanes_lyr')
# Replace a layer/table view name with a path to a dataset
# (which can be a layer file) or create the layer/table view
# within the script
# The following inputs are layers or table views:
# "FireBoxMap", "Street Centerlines"
arcpy.SelectLayerByLocation_management(
in_layer='Lanes_lyr',
overlap_type='INTERSECT',
select_features=fc,
search_distance='',
selection_type='NEW_SELECTION',
invert_spatial_relationship='NOT_INVERT')
laneCount = int(arcpy.GetCount_management('Lanes_lyr').getOutput(0))
print str(laneCount)
# Update field
arcpy.CalculateField_management(in_table=fc, field='LaneMiles',
expression=' [Lanes] * [SHAPE_Length]',
expression_type='VB',
code_block='')
print 'updated LaneMiles field'
except Exception, e:
print e
try
block to go along with theexcept
block?