Hi,
I edited this code and it works fine in the field calculator, but doesn't work as shown below as a stand-alone script. Any suggestions? Thanks.
# Import system modules
import arcpy
import math
from arcpy import env
# Set environment settings
env.workspace = "C:/WorkSpace"
# Set local variables
inFeatures = "testfracs.shp"
fieldName = "Geoangle1"
expression = "GetAzimuthPolyline(!Shape!)"
codeblock = """def GetAzimuthPolyline(shape):
radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y))
degrees = radian * 180 / math.pi
return degrees"""
# Execute AddField
arcpy.AddField_management(inFeatures, fieldName, "SHORT")
#print "Field has been added."
# Execute CalculateField
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON", codeblock)