How do I delete all of the fields from a feature class in a simple way?
I don't want to loop over the fields using the Delete Field tool because this method is very slow in ArcPy.
I am using a polygon feature class, and I tried arcpy.MultipartToSinglepart_management
but the feature class result saved all the fields.
2 Answers 2
I think you could do this with MakeFeatureLayer on your original feature class, using field_info to "hide" all the fields, followed by CopyFeatures to get the features with no fields in a new feature class.
I investigated to make sure that this would work - and it did. Here are some Python snippets of doing the steps manually to get the syntax right.
arcpy.MakeFeatureLayer_management("C:/avhome/arcGISdata/Exploration.gdb/Samples","Samples_Layer","#","#","OBJECTID OBJECTID HIDDEN NONE;SHAPE SHAPE HIDDEN NONE;Dip_Angle Dip_Angle HIDDEN NONE;Strike Strike HIDDEN NONE;Rock Rock HIDDEN NONE;Description Description HIDDEN NONE")
arcpy.CopyFeatures_management("Samples_Layer","C:/avhome/arcGISdata/Exploration.gdb/SamplesNoAtts","#","0","0","0")
The only attributes on output are OBJECTID and SHAPE.
I wish that the ArcInfo Workstation command PULLITEMS had translated into an ArcGIS Desktop tool perhaps named Pull Fields or Filter Fields.
You could work around it by creating a new feature class using the geometries of the old one but without the fields. The ArcGIS Resource Center has a section on working with geometry in Python. There' a section on reading and writing geometries that should cover what you need.
Explore related questions
See similar questions with these tags.