I was wondering if it's possible to use the standard auto increment code to work on groups of records:
FeatureClass = "newFC"
recs = collections.defaultdict(int) autoIncrementEXP = "autoIncrement()"
expCalc = """def autoIncrement(!Group!): recs[!Group!] += 1 return recs[!Group!]"""
arcpy.CalculateField_management(FeatureClass, "Number",autoIncrementEXP,"PYTHON",expCalc)
So instead of having the auto increment portion of the script stop when it reaches the end of the records, have it create sequential numbers using field value groups if that makes sense. You would start with something like the Group
field below and end with the Number
field containing the increment values:
Group Number
A 1
A 2
A 3
B 1
B 2
C 1
C 2
C 3
C 4
C 5
Thanks for any insight you can provide.
Answer
You'll need to pass in the value of your group field to the autoIncrement
function now, but this would work:
import collections
recs = collections.defaultdict(int)
def autoIncrement(field_value):
recs[field_value] += 1
return recs[field_value]
So something like this:
FeatureClass = "newFC"
expCalc = "import collections\n\nrecs = collections.defaultdict(int)\n\ndef autoIncrement(field_value):\n recs[field_value] += 1\n return recs[field_value]\n"
arcpy.CalculateField_management(FeatureClass, "Number", "autoIncrement(!Group!)","PYTHON", expCalc)
No comments:
Post a Comment