Use Python expression in field calculator

2350
6
08-24-2010 12:49 PM
MarcBate
Occasional Contributor II
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
0 Kudos
6 Replies
KirkKuykendall
Occasional Contributor III
This is a good question.
0 Kudos
MarcBate
Occasional Contributor II
This is a good question.


I searched through the Object Browser and couldn't find anything named python that sounded like it applied to the calculator.
0 Kudos
KenBuja
MVP Esteemed Contributor
This has been reported as a bug: NIM061356 (ICalculator or ICalculatorUI2 do not offer a property where the parser (expression type) can be specified; VBScript is the default, so Python expressions error out). Unfortunately, although being submitted over a year ago, it's classified as low priority and has not been fixed yet.
0 Kudos
MarcBate
Occasional Contributor II

I noticed this bug has still not been fixed.  Perhaps because it has 'VBA' as the programming language.  This bug effects any ArcObjects code, so maybe it should be set to .NET or C# ?

0 Kudos
KenBuja
MVP Esteemed Contributor

Usually, Esri support suggests that more people add their name to this issue so it will get a higher priority.

0 Kudos
MarcBate
Occasional Contributor II
It would be nice to put this in the ArcObjects help at least so others aren't pulling their hair out like I was trying to figure this out.   I'm surprised no one else has ran into this issue as much as ESRI is promoting Python in the past year or so.
0 Kudos