Hello, I am fairly new to py programming and have 1/2 copy pasted this and 1/2 developed this to meet my requirements. Most of the script is successful, but the cursor seems to stall after the first record is inserted. I have added all of the code, just in case some of the set up is the problem...
try:
import sys, traceback, os
import arcpy
arcpy.env.overwriteOutput = True
#inDir = arcpy.GetParameterAsText(0)
inDir = "Q:\\CCR\\1.Alexis Creek Flights\\"
#outFile = arcpy.GetParameterAsText(1)
outFile = "Q:\\EntireQDrive.gdb"
print "In Dir: " + (inDir)
print "Out File: " + (outFile)
print "dirname: " + os.path.dirname(outFile)
print "basename: " + os.path.basename(outFile)
FileName = os.path.dirname(outFile) + os.path.basename(outFile)
print "filename: " + (FileName)
arcpy.env.workspace = FileName
feature_classes = []
walk = arcpy.da.Walk(inDir, datatype="RasterDataset", type="All")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
#print (dirpath)
#print (filenames)
feature_classes.append(os.path.join(dirpath, filename))
arcpy.CreateFeatureclass_management(FileName,"CCR", "POLYGON")
print ("Created FC")
fieldName1 = "RasterName"
fieldLength1 = 100
fieldName2 = "RasterPath"
fieldLength2 = 250
arcpy.AddField_management("CCR", fieldName1, "TEXT", fieldLength1)
arcpy.AddField_management("CCR", fieldName2, "TEXT", fieldLength2)
print ("Added Field")
cursor = arcpy.InsertCursor("CCR")
point = arcpy.Point()
array = arcpy.Array()
corners = ["lowerLeft", "lowerRight", "upperRight", "upperLeft"]
#print (feature_classes)
for Ras in feature_classes:
print(Ras)
feat = cursor.newRow()
r = arcpy.Raster(Ras)
for corner in corners:
point.X = getattr(r.extent, "%s" % corner).X
point.Y = getattr(r.extent, "%s" % corner).Y
array.add(point)
array.add(array.getObject(0))
polygon = arcpy.Polygon(array)
feat.shape = polygon
feat.setValue("RasterName", Ras.split('\\')[-1])
feat.setValue("RasterPath", Ras)
cursor.insertRow(feat)
array.removeAll()
del feat
del cursor
print ("")
print ("All Done :)")
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
print pymsg + "\n"
print msgs
Thanks in advance!