AnsweredAssumed Answered

calculate field fails

Question asked by shepa006 on Dec 24, 2014
Latest reply on Dec 29, 2014 by shepa006

I have an IFeatureClass created in my code and I have added a new field to it. I'm stuck on calculating values for the new field. I've tried using CalculateField and ICalculator but I get errors from both (see code below). Any suggestions?

 

IFeatureClass classifiedPolygons_IFC

IFieldEdit2 field

 

     
/*
* Error HRESULT E_FAIL has been returned from a call to a COM component.
* I've also tried casting the IFeatureClass to ITable
*/
CalculateField calculateField = new CalculateField()
{
    in_table = classifiedPolygons_IFC,
    field = classifiedPolygons_IFC.Fields.Field[classifiedPolygons_IFC.Fields.FindField(field.Name)],
    expression = "Calc Val",
    expression_type = "Python"
};
Geoprocessor gp = new Geoprocessor();
gp.Execute(calculateField, null);
                 
     
/*
* "Retrieving the COM class factory for component with CLSID {D676066E-38CA-429A-B846-DA7A8446C52D} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."
*/
ICursor updateCursor = classifiedPolygons_IFC.Update(null, false) as ICursor;// table.Update(null, false);
ICalculator calculator = new Calculator()
{
    Cursor = updateCursor,
    Field = field.Name,
    Expression = "Calc Val"
};
calculator.Calculate();
Marshal.FinalReleaseComObject(updateCursor);

Outcomes