I have a Script(toolbox) to reorder the fields into a file geodatabse and the output is a new feature class with fields in the order specified, is there any way to replace the existing feature by the new input created? I'm using ArcGIS 10.2 here is my script :
import os,string,sys
try:
import arcgisscripting
gp = arcgisscripting.create()
except:
import win32com.client
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
FC_In = sys.argv[1]
NewOrder = sys.argv[2]
FC_Out_WS = sys.argv[3]
FC_Out_Name = sys.argv[4]
strFields = gp.listfields(FC_In)
strNewOrder = NewOrder
Layers = [""]
# Get Field Collection into List
Fields = gp.listfields(FC_In)
NewOrder = string.split(strNewOrder,";")
print Fields
print NewOrder
x=0 #NewOrder enumerator
y=0 #Layers enumerator (first)
# Cycles through the input feature class creating field collections
while x<len(NewOrder):
Fields.Reset()
Field = Fields.Next()
while Field:
FieldName = str(Field.name)
if x<len(NewOrder) and NewOrder[x].lower() == FieldName.lower():
Layers[y] = Layers[y] + FieldName + " " + NewOrder[x] + " VISIBLE"
x=x+1
else:
Layers[y] = Layers[y] + FieldName + " " + FieldName + " HIDDEN"
Field = Fields.Next()
if Field:
Layers[y] = Layers[y] + "; "
FieldName = str(Field.name)
else:
print Layers[y]
Layers.append("")
y=y+1
Layers[y]=""
# Use Field collections to create Layers with proper order until all fields have been used
z=0 #Layers enumerator (second)
LayerList = ""
for Layer in Layers:
if Layer <> "":
if LayerList <> "":
LayerList=LayerList + ";"
LayerList=LayerList + "Layer" + str(z)
print LayerList
gp.MakeFeatureLayer(FC_In, "Layer" + str(z),"#","#",Layer)
gp.addmessage(gp.getmessages()+ "\n")
z=z+1
#Collect Info about Input Feature Class
dsc = gp.describe(FC_In)
fc_in_stype = dsc.shapetype
fc_in_sr = dsc.spatialreference
# Create new empty Feature class with desired fields
try:
gp.CreateFeatureClas(FC_Out_WS,FC_Out_Name,fc_in_stype,LayerList,"#","#",fc_in_sr)
gp.addmessage(gp.getmessages()+ "\n")
except:
gp.addmessage(gp.getmessages()+ "\n")
# Append Records to new feature class
print FC_Out_WS + "\\" + FC_Out_Name
print FC_In
gp.append_management(FC_In, FC_Out_WS + "\\" + FC_Out_Name)
gp.addmessage(gp.getmessages()+ "\n")
del gp