Syntax for Delete Field geoprocessing tool

213
1
09-23-2019 07:50 AM
SusanFarley
New Contributor III

What is the syntax for deleting multiple fields programmatically? For instance, to add fields, it is

List<object> args = new List<Object> { path, FieldNames};

try

{

   IGPResult res = await Georprocessing.ExecuteToolAsync("management.AddFields", Geoprocessing.MakeValueArray(args.ToArray()));

}

I tried DeleteFields with the same Fields and it fails and have not been able to find the syntax for it in searching.

Thank you,

Susan

Tags (2)
0 Kudos
1 Reply
GintautasKmieliauskas
Regular Contributor

Hi Susan,

I am not really sure that DeleteFields tool exists. DeleteField - yes. Try delete one by one field at first.

Next question is the structure of your FieldNames variable. If you use the same FieldNames variable for delete then it will not work, because for adding field you need more than just field name (type, length and etc.). For deleting it is enough only field name.

I have just tested arcpy script where y and x is table field names:

arcpy.management.DeleteField('mytable', "y;x")

It works fine

0 Kudos