I hate to bug you all with the same problem over and over again but I run into a new problem everytime I make a slight change to the code. All I did to the code below was to replace field names to match the original feature class. Now it doesn't work. It gave me
<type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function.
Failed to execute (Script).
I tried adding Try/Except to the code which didn't give me any error messages but didn't give me any results either.
I'm not sure what's going on? Any help to figure this out will be very much appreciated.
import arcpy, os
Try:
roadpath = arcpy.GetParameterAsText(0)
tablepath = arcpy.GetParameterAsText(1)
datapath = os.path.split(tablepath)[0]
tablename = os.path.split(tablepath)[1]
rows = arcpy.SearchCursor(roadpath,"FROMLEFT <> 0 AND TOLEFT <> 0","","STREET_NAME_ID;FROMLEFT;TOLEFT","STREET_NAME_ID A;FROMLEFT A;TOLEFT A")
arcpy.env.workspace = datapath
if arcpy.Exists(tablename):
arcpy.DeleteRows_management(tablename)
else:
arcpy.CreateTable_management(datapath,tablename,roadpath)
arcpy.DeleteField_management(tablename,"SHAPE_Length")
irows = arcpy.InsertCursor(tablename)
first = True
for row in rows:
if first:
first = False
else:
GISID = row.GIS_ID
stid = row.STREET_NAME_ID
fl = row.FROMLEFT
tl = row.TOLEFT
if stid == prev_stid and fl <= prev_tl:
irow = irows.newRow()
irow.GIS_ID = prev_GISID
irow.STREET_NAME_ID = prev_stid
irow.FROMLEFT = prev_fl
irow.TOLEFT = prev_tl
irows.insertRow(irow)
del irow
irow = irows.newRow()
irow.GIS_ID = GISID
irow.STREET_NAME_ID = stid
irow.FROMLEFT = fl
irow.TOLEFT = tl
irows.insertRow(irow)
del irow
prev_GISID = row.GIS_ID
prev_stid = row.STREET_NAME_ID
prev_fl = row.FROMLEFT
prev_tl = row.TOLEFT
del rows, irows
except:
print arcpy.GetMessages()
rows =
toirows
inclusive in a try...except block gives a more revealing error message. It would also help if you can put a sample of the data and full script somewhere (minus.com is one place for easy public sharing).` `
(ref)tablepath
instead oftablename
. This just a forum typo or is it actually like that in the script? The error suggests the former, so can you provide examples of the values you are passing to both of your parameters? Also do you have animport arcpy
line at the top of your script?