Hello.
I've been searching around trying to figure out why this is happening, but can't seem to find much. I tried looking into ESRI's workarounds for this error, but no luck with those.
I am writing a Python script to be used as an Arc tool. I am down to the last 3 lines of code in the script, and I keep getting this 000732 error.
Traceback (most recent call last):
File "C:\Projects\CreateSamples\CreateSamples.py", line 147, in <module>
arcpy.CalculateField_management(sampevents, "SAMPLE_ID", "[FID] + 1", "VB", "")
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 3360, in CalculateField
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset C:\Projects\CreateSamples\SampleFeatureClasses\Sample_Events does not exist or is not supported
Failed to execute (CalculateField).
Failed to execute (CreateSamplesTest).
However, the Sample_Events shapefile in question does in fact exist. It is an output of the previous step in the script. In addition, all paths do work. They are set as workspaces by the user when running the tool. Other data within these folders seems to work fine, but for some reason this one layer is holding me up from finishing this thing.
I can add the shapefile to ArcMap and do the field calc, table export, and event layer creation manually, but ideally it should all work within the script/tool.
Copied the entire script below. Not sure if I am copying it correctly...
Thanks for any help!
import arcpy, sys, string, os, subprocess
centerline = arcpy.GetParameterAsText(0)
stname = arcpy.GetParameterAsText(1)
dtsid = arcpy.GetParameterAsText(2)
width = arcpy.GetParameterAsText(3)
gisdata = arcpy.GetParameterAsText(4)
sampfcdata = arcpy.GetParameterAsText(5)
#Convert centerline into an LRS for creating event layer later.
arcpy.CreateRoutes_lr(centerline, dtsid, gisdata+"\\"+centerline+"_LRS", "LENGTH", "", "", "LOWER_LEFT", "1", "0", "IGNORE", "INDEX")
#TEMP DELETE FIELDS
addfields = 0
with arcpy.da.SearchCursor(centerline, "SAMPINS") as cursor:
for row in cursor:
addfields = max(int(row[0]), addfields)
fieldtag = str(addfields)
while (addfields > 1):
arcpy.DeleteField_management(centerline, ["F_"+fieldtag])
addfields = addfields - 1
fieldtag = str(addfields)
arcpy.DeleteField_management(centerline, ["ADJWIDTH", "ESTAREA", "RAWSAMP", "SAMPLES", "SAMPAREA", "SA_W", "SAMPLF", "ADJAREA", "ADJUSTED", "SAMPINS", "SAMP_1", "SAMPDIST", "SAMPLEN", "SAMPSTRT", "LENGTH", "WIDTH", "SAMPLE_ID", "SEGMENT_ID", "BEGIN_MP", "END_MP"])
#TEMP DELETE FIELDS
#Add and calculate necessary fields to create sample event measures.
arcpy.AddGeometryAttributes_management(centerline, "LENGTH", "FEET_US", "","")
length = "LENGTH"
arcpy.AddField_management(centerline, "ADJWIDTH", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(centerline, "ADJWIDTH", "["+width+"]", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJWIDTH\" > 26")
arcpy.CalculateField_management(centerline, "ADJWIDTH", "26", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
arcpy.AddField_management(centerline, "ESTAREA", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "RAWSAMP", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPLES", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPAREA", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SA_W", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPLF", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "ADJAREA", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "ADJUSTED", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPINS", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMP_1", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPDIST", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPLEN", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SAMPSTRT", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(centerline, "ESTAREA", "["+length+"] * [ADJWIDTH]", "VB", "")
arcpy.CalculateField_management(centerline, "RAWSAMP", "[ESTAREA]/2500", "VB", "")
arcpy.CalculateField_management(centerline, "SAMPLES", "Round(([RAWSAMP] + 0.5),0)", "VB", "")
arcpy.CalculateField_management(centerline, "SAMPAREA", "[ESTAREA] / [SAMPLES]", "VB", "")
arcpy.CalculateField_management(centerline, "SA_W", "[SAMPAREA] / [ADJWIDTH]", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SA_W\" <= 50")
arcpy.CalculateField_management(centerline, "SAMPLF", "50", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SA_W\" > 50 AND \"SA_W\" <= 75")
arcpy.CalculateField_management(centerline, "SAMPLF", "75", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SA_W\" > 75 AND \"SA_W\" <= 125")
arcpy.CalculateField_management(centerline, "SAMPLF", "100", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SA_W\" > 125 AND \"SA_W\" <= 175")
arcpy.CalculateField_management(centerline, "SAMPLF", "150", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SA_W\" > 175")
arcpy.CalculateField_management(centerline, "SAMPLF", "200", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
arcpy.CalculateField_management(centerline, "ADJAREA", "[ADJWIDTH] * [SAMPLF]", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJAREA\" < 1500")
arcpy.CalculateField_management(centerline, "ADJAREA", "1500", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJAREA\" > 3500")
arcpy.CalculateField_management(centerline, "ADJAREA", "3500", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
arcpy.CalculateField_management(centerline, "ADJUSTED", "Round((([ESTAREA] / [ADJAREA]) + 0.5),0)", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJUSTED\" < 6")
arcpy.CalculateField_management(centerline, "SAMPINS", "1", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJUSTED\" >= 6 AND \"ADJUSTED\" < 11")
arcpy.CalculateField_management(centerline, "SAMPINS", "2", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJUSTED\" >= 11 AND \"ADJUSTED\" < 16")
arcpy.CalculateField_management(centerline, "SAMPINS", "3", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJUSTED\" >= 16 AND \"ADJUSTED\" < 41")
arcpy.CalculateField_management(centerline, "SAMPINS", "4", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"ADJUSTED\" > 40")
arcpy.CalculateField_management(centerline, "SAMPINS", "Round(([ADJUSTED] * 0.17),0)", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
arcpy.CalculateField_management(centerline, "SAMP_1", "(["+length+"] - ([SAMPLF]*[SAMPINS])) / ([SAMPINS] + 1)", "VB", "")
arcpy.CalculateField_management(centerline, "SAMPDIST", "[SAMP_1]", "VB", "")
arcpy.CalculateField_management(centerline, "SAMPLEN", "["+length+"]", "VB", "")
arcpy.CalculateField_management(centerline, "SAMPSTRT", "0", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SAMPLEN\" >= 200")
arcpy.CalculateField_management(centerline, "SAMPLEN", "[SAMPLF]", "VB", "")
arcpy.CalculateField_management(centerline, "SAMPSTRT", "[SAMP_1]", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
#Add fields based on the maximum number of samples, and calculate.
addfields = 0
with arcpy.da.SearchCursor(centerline, "SAMPINS") as cursor:
for row in cursor:
addfields = max(int(row[0]), addfields)
fieldtag = str(addfields)
while (addfields > 1):
arcpy.AddField_management(centerline, "F_"+fieldtag, "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"SAMPINS\" > "+fieldtag+" - 1")
arcpy.CalculateField_management(centerline, "F_"+fieldtag, "[SAMPSTRT] + (([SAMPDIST] + [SAMPLF])*("+fieldtag+"-1))", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "SWITCH_SELECTION", "")
arcpy.CalculateField_management(centerline, "F_"+fieldtag, "0", "VB", "")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
addfields = addfields - 1
fieldtag = str(addfields)
#Add fields to improve formatting.
arcpy.AddField_management(centerline, "SAMPLE_ID", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "SEGMENT_ID", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "NAME", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "WIDTH", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "BEGIN_MP", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(centerline, "END_MP", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(centerline, "SEGMENT_ID", "["+dtsid+"]", "VB", "")
arcpy.CalculateField_management(centerline, "NAME", "["+stname+"]", "VB", "")
arcpy.CalculateField_management(centerline, "WIDTH", "[ADJWIDTH]", "VB", "")
arcpy.CalculateField_management(centerline, "BEGIN_MP", "[SAMPSTRT]", "VB", "")
arcpy.CalculateField_management(centerline, "END_MP", "[SAMPSTRT] + [SAMPLEN]", "VB", "")
#Export first sample measures. Only export specific fields.
arcpy.FeatureClassToFeatureClass_conversion(centerline, sampfcdata, "Samples_1", "", "[SAMPLE_ID], [SEGMENT_ID], [NAME], [WIDTH], [LENGTH], [BEGIN_MP], [END_MP]")
#Select based on data that exists in F_n fields, and calculate BMP and EMP fields based on selection. Then, export that selection as a new feature class.
addfields = 0
with arcpy.da.SearchCursor(centerline, "SAMPINS") as cursor:
for row in cursor:
addfields = max(int(row[0]), addfields)
fieldtag = str(addfields)
while (addfields > 1):
arcpy.SelectLayerByAttribute_management(centerline, "NEW_SELECTION", "\"F_"+fieldtag+"\" <> 0")
arcpy.CalculateField_management(centerline, "BEGIN_MP", "[F_"+fieldtag+"]", "VB", "")
arcpy.CalculateField_management(centerline, "END_MP", "[F_"+fieldtag+"]+[SAMPLEN]", "VB", "")
arcpy.FeatureClassToFeatureClass_conversion(centerline, sampfcdata, "Samples_"+fieldtag, "", "[SAMPLE_ID], [SEGMENT_ID], [NAME], [WIDTH], [LENGTH], [BEGIN_MP], [END_MP]")
arcpy.SelectLayerByAttribute_management(centerline, "CLEAR_SELECTION", "")
addfields = addfields - 1
fieldtag = str(addfields)
#Merge all exported feature classes.
arcpy.env.workspace = sampfcdata
fclist = arcpy.ListFeatureClasses()
sampevents = "C:\\Projects\\CreateSamples\\SampleFeatureClasses\\Sample_Events"
arcpy.Merge_management(fclist, sampevents)
#Calculate SAMPLE_ID field.
arcpy.CalculateField_management(sampevents, "SAMPLE_ID", "[FID] + 1", "VB", "")
#Export table.
arcpy.TableToTable_conversion(sampevents, gisdata, "Sample_Events_Table")
#Make route event layer\samples feature class.
arcpy.MakeRouteEventLayer_lr(gisdata+"\\"+centerline+"_LRS", dtsid, gisdata+"Sample_Events_Table", ["LINE", "[BEGIN_MP]", "[END_MP]"], gisdata+"\\"+centerline+"_Samples")
Solved! Go to Solution.
Trying specifying the SHP file extension:
#Merge all exported feature classes.
arcpy.env.workspace = sampfcdata
fclist = arcpy.ListFeatureClasses()
sampevents = "C:\\Projects\\CreateSamples\\SampleFeatureClasses\\Sample_Events.shp"
arcpy.Merge_management(fclist, sampevents)
You might want to put in some print statements to make sure intermediate steps are processing correctly especially for the variables that are being fed into the last task arcpy.MakeRouteEventLayer_lr.
Also when you post code on GeoNet please use the instructions from this document: https://community.esri.com/docs/DOC-8691-posting-code-with-syntax-highlighting-on-geonet . That will make it easier to debug code and avoids indents from being removed from the code you post.
Awesome. Thank you! Edited!
Are all of the Feature Classes in "fclist" of the same type?
fclist = arcpy.ListFeatureClasses()
Also, you may want to see if this is a source/path issue. I've run into that error on SDE feature classes if I simply set a variable reference to the full/complete path and had to break it up and use os.path.join() to build a reference to the feature class.
#instead of this
sampevents = "C:\\Projects\\CreateSamples\\SampleFeatureClasses\\Sample_Events"
#try this
ws = r"C:\Projects\CreateSamples\SampleFeatureClasses"
fcname = r"Sample_Events"
sampvents = os.path.join(ws, fcname)
Yes, they are all the same. They are all a result of a previous step, too. The original feature class being used is a line shapefile, and everything else in the script is derived from that file.
I tried entering the absolute path in place of the variable (copy/pasted from Windows Explorer), too, and that produced the same error.
Did you try my suggestion to build the sampvents variable?
It just finished running, and produced the same error.
And it successfully merges after this line?
arcpy.Merge_management(fclist, sampevents)
The error says it's failing on line 137
arcpy.CalculateField_management(sampevents, "SAMPLE_ID", "[FID] + 1", "VB", "")
Which it would be logical if the above failed.
Yes, the merge is successful, and I can pull the Sample_Events layer into ArcMap and do the field calc manually, and it works fine.
The error occurs at line 147, which is the calculate field tool on the SAMPLE_ID field.