jtrook

difficulty calculating field in Python

Discussion created by jtrook on May 2, 2014
Latest reply on May 2, 2014 by eibenm
Hi All,
I'm having difficulty calculating a field in my Python script.  I have a bunch of polylines and I want to get the azimuth for each line in degrees.
This is where my code crashes (the math module has already been imported):

fieldName3 = "Azimuth"
expression2 = "180+math.atan2(( !Shape.firstpoint.X! - !Shape.lastpoint.X! ),( !Shape.firstpoint.Y! - !Shape.lastpoint.Y! ) ) * (180 / math.pi )"
arcpy.CalculateField_management(outFeatureClass, "Azimuth", expression2, "PYTHON")  


I get an arcgisscripting.ExecuteError: ERROR 000539:
The confusing thing is I can paste the same code in the field calculator and it works fine.

Thanks in advance for you help,
Jason

Outcomes