Dear All,
I've Tried to Add Field using arcpy library but the application always close when I run the code, is there any ideas about this situation?
Thank you
Here is my code:
Solved! Go to Solution.
After you save your mxd try getting a reference to the data frame and then the layers in the frame and looping through those:
df = arcpy.mapping.ListDataFrames(mxd,"YourDataFrameNameHere")[0]
for fc in arcpy.mapping.ListLayers(mxd, data_frame=df):
arcpy.AddField_management(fc,"Name","TEXT",field_length=50)
This code is going to add the attribute "Name" to every feature class in the data frame.
After you save your mxd try getting a reference to the data frame and then the layers in the frame and looping through those:
df = arcpy.mapping.ListDataFrames(mxd,"YourDataFrameNameHere")[0]
for fc in arcpy.mapping.ListLayers(mxd, data_frame=df):
arcpy.AddField_management(fc,"Name","TEXT",field_length=50)
This code is going to add the attribute "Name" to every feature class in the data frame.
Dear Kim,
Yes, That's true, after I am looking back at my ArcMap version, I am currently using an old version, and that script will work for at least 10.6 version, Thanks 🙂