I have got my code,below, successfully completed and tested. I am trying to cross walk it to a GP tool for my customers. I am, however, encountering design considerations based on how the user wants to interact with the tool.
In the tool, I envision the following:
Parameter 1: Navigate to input workspace
Parameter 2: Show a selection menu of the feature classes in the workspace (as called by the code)
Parameter 3: Show a selection menu of the fields in the selected feature class (as called by the code)
...After selecting the attribute field they wish the auto-increment they would click OK.
I read several resources yet only seemed to provide only very basic knowledge. Alas, I am stuck...
Code:
import arcpy
arcpy.env.workspace = #input workspace
#Iterate through each feature class in the workspace and create list of text data type attribute fields that have field length equal to or greater than the root name of the feature class plus 6 characters
fldnames=[]
lstfc = sorted(arcpy.ListFeatureClasses())
for fc in lstfc:
for f in arcpy.ListFields(fc,"","String"):
if f.length >= int(len(str.split(str(fc),'_')[0])+6):
fldnames.append(f.name)
#Auto-increment each record in the attribute fields in each feature class by 1 populating the rows with the root name of the feature class plus 6 characters
for fld in fldnames:
count=0
cursor=arcpy.UpdateCursor(fc)
for row in cursor:
count+=1
newstr = str(count)
newfld=str(fld)
row.setValue(newfld,str.split(str(fc),'_')[0]+newstr.zfill(6))
cursor.updateRow(row)Parameter 1: Navigate to input workspace
Parameter 2: Show a selection menu of the feature classes in the workspace (as called by the code)
Parameter 3: Show a selection menu of the fields in the selected feature class (as called by the code)
...After selecting the attribute field they wish the auto-increment they would click OK.
I read several resources yet only seemed to provide only very basic knowledge. Alas, I am stuck...