Select to view content in your preferred language

arcpy.CalculateField_management Error

4345
19
Jump to solution
04-14-2014 08:16 AM
DanielJimenez2
Occasional Contributor
I'm using the arcpy lib in arcgis 10.1 and to work on a script. When i use the arcpy.CalculateField_management i'm getting an error . Could someone help me identify whats wrong with the expression below. I'm using VB because when i use the python calculator, python crashes at the end of the calculation so VB is the only option i have. Notice that this expression work good when using python but like i mentioned, when the python option is used. python crashes at the end of the script.

arcpy.CalculateField_management("TAZ_un_Buffer_Dissolve.shp", "totalArea","[shape.area]", "VB", "")


Traceback (most recent call last):   File "D:\CubeAlbuquerque\AlbuquerqueNewTAZ\02_Applications\02_Transit_walk_Acc ess\ptaccess_SM.py", line 55, in <module>     arcpy.CalculateField_management("TAZ_un_Buffer_Dissolve.shp", "totalArea","[ shape.area]", "VB", "")   File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", li ne 3128, in CalculateField     raise e arcgisscripting.ExecuteError: ERROR 999999: Error executing function. Failed to execute (CalculateField).
Tags (2)
0 Kudos
19 Replies
IanMurray
Honored Contributor
Yes, like i said when i used the caluclate filed python expression the script works, but it crashes when it finish working. I can open the shapefile and see all the fields and their values. Now i dont know why python crashes when i do this and i dont know how to debug something like this.


Yea, that's significantly uglier than I was expected, I didn't realize when you said "crash" you meant crash like that.  Reminds me of the time I had a script that would just stop in different places, it would process between 30-40 files (out of like 600) and then just stop, no error codes, no nothing, just would stop, and in a different place each time.  First time 25 files, next 40, next 32.  Finally got a computer with a better processer and more memory and it managed to do all of the files in one go.
0 Kudos
DanielJimenez2
Occasional Contributor
Hello Daniel,

Very tricky indeed. I couldn't see much from your screenshot (the resolution was too low), but I see how that is a hard problem to solve. If you comment out the arcpy.CalculateField_management line, does it run successfully without crashing at the end?


No, line 65 will also present a problem, but it also is related to the same topic. Im attaching a better pic just in case.


[ATTACH=CONFIG]33075[/ATTACH]
0 Kudos
MichaelVolz
Esteemed Contributor
Can you check to see if Background Geoprocessing is enabled (default value)?  If Background Geoprocessing is enabled, can you disable it and run your script with Python again.
0 Kudos
DanielJimenez2
Occasional Contributor
Can you check to see if Background Geoprocessing is enabled (default value)?  If Background Geoprocessing is enabled, can you disable it and run your script with Python again.



It was enabled. I disable it but im getting the same issue.
0 Kudos
MichaelVolz
Esteemed Contributor
Can you make a backup of your shapefile and then delete almost all records leaving just 2 or 3 and then run the script on that shapefile to see if it runs correctly with python?
0 Kudos
DanielJimenez2
Occasional Contributor
Can you make a backup of your shapefile and then delete almost all records leaving just 2 or 3 and then run the script on that shapefile to see if it runs correctly with python?


Same problem. For some reason i dont know why, the version of python that i have is not good. Seems like everyone can calculate fields using a python expression, but i cant and i dont know how to fix it
0 Kudos
JoshuaChisholm
Frequent Contributor
So just to confirm,

  1. Will the script will work if you take out all the arcpy.CalculateField_management lines?

  2. Will the script will work if you use VB on all the arcpy.CalculateField_management lines? (even if you are just filling the field with 1's)

Also, can you try getting rid of the "#" at the end of the arcpy.CalculateField_management lines?
In other words, change this:
arcpy.CalculateField_management("TAZ_un_Buffer_Dissolve.shp","TotalArea","!Shape.area!","PYTHON","#")

To this:
arcpy.CalculateField_management("TAZ_un_Buffer_Dissolve.shp","TotalArea","!Shape.area!","PYTHON")
0 Kudos
IanMurray
Honored Contributor
So just to confirm,
arcpy.CalculateField_management("TAZ_un_Buffer_Dissolve.shp","TotalArea","!Shape.area!","PYTHON","#")

To this:
arcpy.CalculateField_management("TAZ_un_Buffer_Dissolve.shp","TotalArea","!Shape.area!","PYTHON")


I had him do that in the code I wrote him, so I don't think that's the issue.
0 Kudos
JoshuaChisholm
Frequent Contributor
Maybe try setting "field_precision" and "field_scale" in the arcpy.AddField_management lines?
Something like:
arcpy.AddField_management("TAZ_un_Buffer_Dissolve.shp", "TotalArea", "DOUBLE", 10, 10)

I think some of the other parameters are for geodatabases only.
0 Kudos
DanielJimenez2
Occasional Contributor
Thanks for all the help but I think I fixed the problem. The computer had two versions of python 27 installed and seems that that is the reason behind python crashing when using the CalcFiled method. I removed the version Arcgis does not use and it is not crashing anymore so its working normal now. Thanks for the help
0 Kudos