Hey community,
Very infrequent poster here, so I'll try my very best to explain this with as much detail as possible.
I'm trying to write a bespoke script tool for ArcGIS Pro (2.7) using Python (3.7).
I'm trying to use an UpdateCursor to update the rows of a .dbf table (outDBFTable). But when I run the script, I get the classic error "TypeError: sequence size must match size of the row". But when diagnostics 2 and 4 run, it appears the rows do in fact have the same number of elements.
outDBFTable attributes:
OBJECTID | field1 | field2 | field3 | field4 | ... |
1 | <Null> | <Null> | ... | | |
2 | <Null> | ... | | | |
3 | ... | | | | |
4 | | | | | |
5 | | | | | |
6 | | | | | |
7 | | | | | |
rasTable attributes:
OBJECTID | Count |
1 | <number> |
2 | ... |
3 | |
4 | |
5 | |
6 | |
7 | |
...
counter2 = 0
with arcpy.da.SearchCursor(inPoly,"SHAPE@") as sCursor2:
for sRows2 in sCursor2:
maskExtract = arcpy.sa.ExtractByMask(reclassRas,sRows2)
rasTable = arcpy.management.BuildRasterAttributeTable(maskExtract)
arcpy.AddMessage(rasTable) # diagnostics 1
with arcpy.da.SearchCursor(rasTable,("Value","Count")) as sCursor3:
for sRows3 in sCursor3:
arcpy.AddMessage(sRows3) # diagnostics 2
with arcpy.da.UpdateCursor(outDBFTable,("OBJECTID",fieldList[counter2])) as uCursor1:
arcpy.AddMessage(uCursor1)# diagnostic 3
for uRows1 in uCursor1:
arcpy.AddMessage(uRows1) # diagnostics 4
if sRows3[0] == uRows1[0]:
arcpy.AddMessage("true true") # diagnostics 5
uCursor1.updateRow([sRows3[1]]) # <- Error raised here
else:
arcpy.AddMessage("false false") # diagnostics 6
counter2 =+ 1
del (sCursor2)
del (sCursor3)
del (uCursor1)
...
Every time sCursor2 performs its task and produces a new rasTable, I want to use the "Count" column <number> from rasTable to update outDBFTable fields where outDBFTable "OBJECTID" == rasTable "OBJECTID". The counter is in there to position the cursor over the correct field from fieldList (field1, field2...) every time a new rasTable is produced. Mechanically, I'm confident all of this works because if I comment out "uCursor1.updateRow([sRows3[1]])", the printout in the ArcGIS Pro tool message dialogue box behaves just as I expect. Or based on the error, I'm overly confident...
Basically, I don't understand why I'm getting a sequence size error when the diagnostics show the rows to be the same size.
I've attached a image of the error dialogue.
Please let me know if more information is needed.
Any help would be great!