I need to be able to export the selected attributes from Arcmap. I have the following but I get an error on line 32. The first arcpy.Addmessage does print the OID's but not the second Addmessage. My guess is that it's not creating the temp_view. How can I get past this error?
error on line 32
ERROR 000732: Input Table: Dataset tmp_view does not exist or is not supported
Failed to execute (TableToExcel)
selection = "NParcels"
try:
if int(arcpy.GetCount_management(selection).getOutput(0)) > 0:
arcpy.CopyRows_management(selection, "selct")
arcpy.MakeTableView_management("selct","selectionView")
fc = "selectionView"
desc = arcpy.Describe(fc)
oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
arcpy.AddMessage(oidList)
flds = [fld.name for fld in desc.fields]
flds_remove = [desc.OIDFieldName,
desc.shapeFieldName,
desc.areaFieldName,
desc.LengthFieldName]
for fld in flds_remove:
flds.remove(fld)
arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)
oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
arcpy.AddMessage(oidList)
except:
pass
wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'
arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Notification' + OutputExt)K