AnsweredAssumed Answered

Use Python expression in field calculator

Question asked by MarcBate on Aug 24, 2010
Latest reply on Feb 23, 2016 by kenbuja
I get an error when using a Python expression in the field calculator in ArcGIS 10 using ArcObjects.  The expression works fine when using the GUI.

I can't see where to set the parser to Python instead of VBScript using ICalculator.

I am using .NET, but made this simple VBA routine for testing, where it updates the last field with the logp of the field named SumOfConcentrations


Public Sub TestPythonCalc()
 Dim fc As IFeatureClass
 Set fc = GetLayer0.FeatureClass
 
 Dim calc As ICalculator
 Set calc = New Calculator
 
 With calc
   Set .Cursor = fc.Update(Nothing, False)
   .Expression = "math.log1p(!SumOfConcentrations!)"
   .Field = fc.Fields.Field(fc.Fields.FieldCount - 1).Name
   .ShowErrorPrompt = False
   .Calculate
 End With
 
End Sub

Private Function GetLayer0() As IGeoFeatureLayer

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim pGFL As IGeoFeatureLayer
Set pGFL = pMxDoc.FocusMap.Layer(0)

Set GetLayer0 = pGFL
End Function

Outcomes