Hello i have written the following script to iterate it as a tool for all my tables with modelbuilder, but i have a problem wth my codeblock. I want to add a field FID to all my tables and to add the values 0,1,2,3,4... for all rows of table. Each table has different number of rows. I am using ArcGis 10.2.2
The code i have written is this.
# Import system modulesimport arcpyimport osfrom arcpy import envarcpy.overwriteoutput = True# Set environment settingsinWorkspace = arcpy.GetParameterAsText(0)inTable = arcpy.GetParameterAsText(1)outTable = arcpy.GetParameterAsText(2)data_type = ""# Set local variables# fieldName1 # fieldName2 fieldName1 = "FID_1"fieldName2 = "Same"arcpy.AddField_management(inTable, fieldName1, "DOUBLE", "", "", "", "", "NON_NULLABLE")arcpy.AddField_management(inTable, fieldName2, "DOUBLE", "", "", "", "", "NON_NULLABLE")arcpy.Copy_management(inTable, outTable, data_type)# Calculate Field FID_1fieldname = fieldName1expression = "getCalc(!FID_1!)"codeblock = """def getCalc(FID_1): FID_1 = 1 for row in FID_1: FID_1 = FID_1 + 1 return FID_1"""# Execute CalculateField arcpy.CalculateField_management(inTable, fieldname, expression, "PYTHON_9.3", codeblock)I am newbie in Python so every help is appreciated a lot, thank you
أكثر...
The code i have written is this.
# Import system modulesimport arcpyimport osfrom arcpy import envarcpy.overwriteoutput = True# Set environment settingsinWorkspace = arcpy.GetParameterAsText(0)inTable = arcpy.GetParameterAsText(1)outTable = arcpy.GetParameterAsText(2)data_type = ""# Set local variables# fieldName1 # fieldName2 fieldName1 = "FID_1"fieldName2 = "Same"arcpy.AddField_management(inTable, fieldName1, "DOUBLE", "", "", "", "", "NON_NULLABLE")arcpy.AddField_management(inTable, fieldName2, "DOUBLE", "", "", "", "", "NON_NULLABLE")arcpy.Copy_management(inTable, outTable, data_type)# Calculate Field FID_1fieldname = fieldName1expression = "getCalc(!FID_1!)"codeblock = """def getCalc(FID_1): FID_1 = 1 for row in FID_1: FID_1 = FID_1 + 1 return FID_1"""# Execute CalculateField arcpy.CalculateField_management(inTable, fieldname, expression, "PYTHON_9.3", codeblock)I am newbie in Python so every help is appreciated a lot, thank you
أكثر...