2

I'm trying to add multiple fields to multiple feature classes using a list in ArcGIS Pro. This is my code

import arcpy
 
arcpy.env.workspace = "Tatjana\MasterGeodatabase\MasterGeodatabase.gdb"
FcList = ['Storm Control Valves', 'Storm Culverts', 'Storm Detention Areas', 'Storm Discharge Points', 'Storm Fittings', 'Storm Gravity Mains', 'Storm Inlets', 'Storm Manholes', 'Storm Network Structures', 'Storm Pressure Mains', 'Storm System Valves']
for fc in FcList:
 arcpy.management.AddFields(fc, 'CONDSCORE', 'FLOAT', 'Condition Score', None, "", "")
 arcpy.management.AddFields(fc, 'CONDDATE', 'DATE', 'Condition Date', None, "", "")
 arcpy.management.AddFields(fc, 'ESTSERVICELIFE', 'FLOAT', 'Est. Service Life', None, "", "")
 arcpy.management.AddFields(fc, 'COST', 'FLOAT', 'Asset Cost', None, "", "")
 arcpy.management.AddFields(fc, 'LIFECYCLESTS', 'TEXT', 'Lifecycle Status', 255, "", "")
 arcpy.management.AddFields(fc, 'RESIDUALLIFE', 'FLOAT', 'Residual Life', None, "", "")
 arcpy.management.AddFields(fc, 'ESTREPLCCOST', 'FLOAT', 'Est. Replacement Cost', None, "", "")
 arcpy.management.AddFields(fc, 'ESTREPLCDATE', 'DATE', 'Est. Replacement Date', None, "", "")
 arcpy.management.AddFields(fc, 'PCTSVCLIFEUSED', 'FLOAT', '% Service Life Consumed ', None, "", "")

When I run the code this is the error I'm getting

TypeError: AddFields() takes from 0 to 2 positional arguments but 7 were given
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 1, 2022 at 17:35
2

1 Answer 1

2

You are using AddField syntax. AddFields takes a feature class and single list of field descriptions as a parameter. Either use AddField or convert your code to use AddFields syntax. E.g.

AddField:

for fc in FcList:
 arcpy.management.AddField(fc, 'CONDSCORE', 'FLOAT', 'Condition Score', None, "", "")
 arcpy.management.AddField(fc, 'CONDDATE', 'DATE', 'Condition Date', None, "", "")
 arcpy.management.AddField(fc, 'ESTSERVICELIFE', 'FLOAT', 'Est. Service Life', None, "", "")
 arcpy.management.AddField(fc, 'COST', 'FLOAT', 'Asset Cost', None, "", "")
 arcpy.management.AddField(fc, 'LIFECYCLESTS', 'TEXT', 'Lifecycle Status', 255, "", "")
 arcpy.management.AddField(fc, 'RESIDUALLIFE', 'FLOAT', 'Residual Life', None, "", "")
 arcpy.management.AddField(fc, 'ESTREPLCCOST', 'FLOAT', 'Est. Replacement Cost', None, "", "")
 arcpy.management.AddField(fc, 'ESTREPLCDATE', 'DATE', 'Est. Replacement Date', None, "", "")
 arcpy.management.AddField(fc, 'PCTSVCLIFEUSED', 'FLOAT', '% Service Life Consumed ', None, "", "")

AddFields:

for fc in FcList:
 arcpy.management.AddFields(fc, [
 ['CONDSCORE', 'FLOAT', 'Condition Score', None, "", ""],
 ['CONDDATE', 'DATE', 'Condition Date', None, "", ""],
 ['ESTSERVICELIFE', 'FLOAT', 'Est. Service Life', None, "", ""],
 ['COST', 'FLOAT', 'Asset Cost', None, "", ""],
 ['LIFECYCLESTS', 'TEXT', 'Lifecycle Status', 255, "", ""],
 ['RESIDUALLIFE', 'FLOAT', 'Residual Life', None, "", ""],
 ['ESTREPLCCOST', 'FLOAT', 'Est. Replacement Cost', None, "", ""],
 ['ESTREPLCDATE', 'DATE', 'Est. Replacement Date', None, "", ""],
 ['PCTSVCLIFEUSED', 'FLOAT', '% Service Life Consumed ', None, "", ""]])
answered Sep 1, 2022 at 21:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.