| Message |
I'm building a custom GeoProcessing tool for 9.3 using VS.NET 2008 (C#).
When I add a field to a FeatureClass, then attempt to calculate the field using the CalculateField tool, it returns "ERROR 000728: Field COCALC does not exist within table". Inspecting the FeatureClass afterwards shows that the field was in fact added!
This is true whether I add the field using the AddField tool or IFeatureClass.AddField, and whether I obtain a schema lock. This works fine in a Python script tool using AddField_management followed by CalculateField_management.
I know the CalculateField code is valid, because it works if the field exists before the tool is run.
Where might the problem lie?
Thanks in advance,
Randal |
| |
public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message)
{
Geoprocessor gp = new Geoprocessor();
IGPValue inputPolygonFeatureClass = m_GPUtilities.UnpackGPValue(paramvalues.get_Element(0));
IFeatureClass featureClass;
IQueryFilter qf;
m_GPUtilities.DecodeFeatureLayer(inputPolygonFeatureClass, out featureClass, out qf);
ISchemaLock schemaLock = (ISchemaLock)featureClass;
IFieldEdit newField = new FieldClass();
newField.Type_2 = esriFieldType.esriFieldTypeInteger;
newField.Name_2 = "COCALC";
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
featureClass.AddField(newField);
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
// Execute in this block fails with error "ERROR 000728: Field COCALC does not exist within table"
CalculateField calculateFieldTool = new CalculateField();
calculateFieldTool.in_table = inputPolygonFeatureClass;
calculateFieldTool.field = "COCALC";
calculateFieldTool.expression_type = "VB";
calculateFieldTool.expression = "x";
calculateFieldTool.code_block = "x = 1";
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
gp.Execute(calculateFieldTool, trackcancel);
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
} |