Select to view content in your preferred language

Inconsistent CalculateField with python vs VB

4684
20
Jump to solution
09-16-2014 07:52 AM
alicexu
Deactivated User

result of arcpy.CalculateField_management with python is inconsistent but with VB, it is ok

0 Kudos
20 Replies
alicexu
Deactivated User

But I got an error when I use VB option in my python scripts:

# Import arcpy module

import arcpy

# Local variables:

temp = "S:\\AVM\\ArcCatalogAvmConnections\\ro_gis(AVM).sde\\avm.AVM.Parcel_PolyOnly_Select_Ident1"

# Process: Calculate Field

arcpy.CalculateField_management(temp, "ft", "[shape.area]", "VB", "")

0 Kudos
RichardFairhurst
MVP Honored Contributor

I ran the following script using SDE under SQL server and it worked without error:

# Import arcpy module

import arcpy

# Local variables:

temp = r"C:\Users\RFAIRHUR\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Trans Connection to SQL Server.sde\GDB_TRANS.TRANS.Test_Area"

# Process: Calculate Field

arcpy.CalculateField_management(temp, "ft", "[Shape.STArea()]", "VB", "")

But I noticed that I have never had a field name called [Shape.area].  In my file geodatabase it is [Shape_area} and in my SDE database it is [Shape.STArea()].  But this could be a difference in the way my SDE administrator set my SDE geometry defaults up.

The script is being run on a computer with an Advanced Desktop license install.  I have never used ArcGIS Engine license if that is what you are using.  You would have to pose your question to users of Engine if that is what you are using.

This may be an installation option issue.  I also do not do ArcGIS installations, so if my IT staff enabled some option that lets my script run that was not enabled when your install was done, I would not know what option that might have been,  I only know that with Desktop installs there is a way to get VB Field Calculations to work within Python scripts.

alicexu
Deactivated User

Thanks Richard. I'm going to set up a job in sql to see if this works for me...

0 Kudos
alicexu
Deactivated User

Richard, I tried in sql and got an error:

File "C:\AVM\SDELog\2.py", line 17, in <module>  arcpy.CalculateField_management(temp, "ft", "[shape.area]", "VB", "")File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 3354, in CalculateField  raise e  arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.  ERROR 000989: Tool CalculateField cannot use VB expressions for services  Failed to execute (CalculateField).  Process Exit Code 1.  The step failed.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here's my python codes for this job in sql:

# Import arcpy module

import arcpy

# Local variables:

temp = r'C:\AVM\AVM @ RO_GIS - AVM.sde\avm.AVM.Parcel_PolyOnly_Select_Ident1'

# Process: Calculate Field

arcpy.CalculateField_management(temp, "ft", "[shape.area]", "VB", "")

0 Kudos
RichardFairhurst
MVP Honored Contributor

I have never processed a script on a service, only on normal SDE connections through Desktop, so this may be a restriction when you are using services.

In that case, I have no solution for your problem if you are using services other than to run your nightly scripts against the Desktop SDE connection and replicate the result to the service.  All versions of python will always simplify all of your true curves when they operate on your geometry and you will see a change the in the area output from what you see in the area field.  Your only other option would be to permanently convert all of the polygons with true curves to high density N-gons to get both the VB Script and the Python calculations to return the same reported area shown in the shape.area field.

So if this was all done against a standard Desktop SDE connection you could use a VB Script calculation in a nightly Python script, but the same is not necessarily true for an SDE service.  So the details of every aspect of your set up can be significant in determining the cause of the behavior and the different configurations of your data storage, software, database connections, etc. can all play a key role in the behavior of a given process.

0 Kudos
alicexu
Deactivated User

Thanks Richard.

I’ll try the sql route to get this. Thank you very much for your helps!

Alice

0 Kudos
curtvprice
MVP Esteemed Contributor

> But I got an error when I use VB option in my python scripts

Make sure your Python script is running in 32-bit Python. Calculate Field's VB parser is only supported with 32-bit arcpy, in 64-bit you must use PYTHON or PYTHON_9.3 or the tool fails.

0 Kudos
alicexu
Deactivated User

Curtis,

Thanks for your reply. How can I specify to use 32-bit Python when I run the Python scripts?

Alice

0 Kudos
curtvprice
MVP Esteemed Contributor

On Windows, you'd run the python script with something like this:

cmd /c C:\python27\ArcGIS10.1\python.exe myfile.py

You can also configure your IDE shortcut to run 32-bit (the default IDLE Python is the last one installed -- usually 64 bit). This of course varies by IDE. For example, I have an IDLE-32 windows shortcut that uses this execute line:

C:\Python27\ArcGIS10.1\pythonw.exe "C:\Python27\ArcGIS10.1\Lib\idlelib\idle.pyw"

0 Kudos
alicexu
Deactivated User

Thanks Curtis. I tried and got this error...

0 Kudos