Python script keep producing error 000732

4579
19
Jump to solution
09-26-2017 11:30 AM
by Anonymous User
Not applicable

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")
0 Kudos
19 Replies
JamesCrandall
MVP Frequent Contributor

One last thing to check is that the fields exist in your CalculateField_management parameters.  I know sometimes fields get renamed or added to an output that is being merged with other data.  And review the actual fieldname not just the alias for SAMPE_ID and FID.

Other than that, only other time I've run into that 000732 is when I didn't have path references joined instead of fully qualified.

Instead of this:

#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", "")

Implement this:

#Merge all exported feature classes.
arcpy.env.workspace = sampfcdata
fclist = arcpy.ListFeatureClasses()
ws = r"C:\Projects\CreateSamples\SampleFeatureClasses"
fcname = r"Sample_Events"
sampvents = os.path.join(ws, fcname)
arcpy.Merge_management(fclist, sampevents)
#Calculate SAMPLE_ID field.
arcpy.CalculateField_management(sampevents, "SAMPLE_ID", "[FID] + 1", "VB", "")
by Anonymous User
Not applicable

I'm still pretty new at all this coding stuff. Been putting this together over the course of the last 2-3 months, and its been step by step for me. I have verified the results after every step, and everything is working correctly. This is something I am bringing over from an older process involving Excel formulas and an outside .exe file. I have an example that was previously done, and I am using the same data as that example...so I have verified that everything up to the calculate SAMPLE_ID field step works correctly.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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)
JamesCrandall
MVP Frequent Contributor

I need to quit speedreading these OP's for little important details like that. heh.

by Anonymous User
Not applicable

Perfect! This worked. So many times I have done this kind of stuff without specifying .shp at the end and its worked, so I never thought to add that in. Thank you!

Got the calculate field and the table export working, now. Moving on to testing the even layer at the end.

JamesCrandall
MVP Frequent Contributor

Please mark Josua's post as the correct answer so other's will be able to see the resolution! 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Without explicitly giving the extension, you are letting different parts of the software make assumptions for you, which is never a good thing.  It is arguable what you ran into is a bug, but I am guessing Esri would simply state you need to provide the extension too.

>>> 
>>> fc_list = [fc, fc1, fc2]
>>> no_ext = arcpy.Merge_management(fc_list, r"D:\tmp\no_ext")
>>> print no_ext.getOutput(0)
D:\tmp\no_ext
>>>
>>> with_ext = arcpy.Merge_management(fc_list, r"D:\tmp\with_ext.shp")
>>> print with_ext.getOutput(0)
D:\tmp\with_ext.shp

When you don't provide the extension, the Result—Help | ArcGIS Desktop object takes your output argument literally and returns it back to you.  Behind the scenes, the merge tool assumed you wanted a shape file and thus created a shape file, but the result object wasn't aware.

Follow the PEP 20 -- The Zen of Python | Python.org :  "Explicit is better than implicit"

JamesCrandall
MVP Frequent Contributor
import this
0 Kudos
by Anonymous User
Not applicable

Definitely helpful to know this for the future. Thanks!

0 Kudos
StevenHaymes1
New Contributor

I highly recommend that you do not build your argument strings inside of the ArcPy functions and instead built them outside of the ArcPy functions, assign them to a variable and then pass the variable as an argument to the ArcPy function.  What you are doing is a dangerous programming technique and given the problems that the underlying ArcPy argument parsing function gp_fixargs has, it is even more dangerous.

0 Kudos