I am trying to add a field to a specific number of feature classes, the names of the feature classes are Pumpcapacities_1
, Pump capacities_2
, Pump capacities_3
.
Each one of these feature classes are located in the same geodatabase, my idea was to use arcpy.ListFeatureClasses("Pump*","Point")
in order to select only the feature classes that start with Pump. But it's not working, each one of those feature classes are in a different feature dataset.
[![enter image description here][1]][1]
import arcpy
arcpy.env.workspace = r"C:\Users\mviera\Documents\CWADigitizeSchemaWorking.gdb"
Feature = arcpy.ListFeatureClasses("Pump*","Point")
for dataset in Feature
arcpy.AddField_management(dataset, "INDPumpCapacity","TEXT",50,"","","IND Pump Capacity","NULLABLE","NON_REQUIRED")
print dataset
-
Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. A question asking for help with code should include a tested code attempt, as text rather than an image, with details about what happens when you run the code. Please edit your question to replace your image with a text code snippet.Midavalo– Midavalo ♦2017年03月17日 14:17:42 +00:00Commented Mar 17, 2017 at 14:17
2 Answers 2
Instead of using arcpy.ListFeatureClasses, since you already know the feature classes which you want to add a field to, you can just create a list which stores their names and iterate through the list:
import arcpy
arcpy.env.workspace = "C:\\Users\\mviera\\Documents\\CWADigitizeSchemaWorking.gdb"
FcList = ["Pumpcapacities_1",
"Pump capacities_2",
"Pump capacities_3"]
for fc in FcList:
arcpy.management.AddField(fc,"INDPumpCapacity","TEXT",50,"","","IND Pump Capacity", "NULLABLE", "NON_REQUIRED")
print fc
You need to loop through your Feature Datasets first.
import arcpy
arcpy.env.workspace = r"C:\Users\mviera\Documents\CWADigitizeSchemaWorking.gdb"
datasets = arcpy.ListDatasets(feature_type = 'Feature')
datasets = [''] + datasets if datasets is not None else []
for ds in datasets:
Feature = arcpy.ListFeatureClasses("Pump*", "Point", ds)
for fc in Feature:
arcpy.AddField_management(fc, "INDPumpCapacity", "TEXT", 50, "", "", "IND Pump Capacity")
print fc
This was based on the code sample at the bottom of ListFeatureClasses - ArcGIS Desktop help