Trying to convert some of my ArcMap Scripts to Pro, I am having a hard time with the arcpy.AddGeometryAttributes_management. but I keep getting the error and currently Running this in python window in Pro to test before I put it in a Pro toolbox script. I need some help please.
Error:
Traceback (most recent call last):
File "<string>", line 23, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 3724, in AddGeometryAttributes
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 3721, in AddGeometryAttributes
retval = convertArcObjectToPythonObject(gp.AddGeometryAttributes_management(*gp_fixargs((Input_Features, Geometry_Properties, Length_Unit, Area_Unit, Coordinate_System), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Traceback (most recent call last):
File "c:\program files\arcgis\pro\Resources\ArcToolbox\scripts\AddGeometryAttributes.py", line 397, in <module>
addGeomAtts.execute()
File "c:\program files\arcgis\pro\Resources\ArcToolbox\scripts\AddGeometryAttributes.py", line 98, in execute
edit.stopEditing(True)
RuntimeError: start edit session
Code:
import arcpy, string, os
workspace = r"C:\Users\***\AppData\Roaming\Esri\ArcGISPro\Favorites\Server.sde"
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyr = m.listLayers("FC_layer")[0]
workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
##
if int(arcpy.GetCount_management(lyr).getOutput(0)) > 0:
arcpy.AddGeometryAttributes_management(lyr,"POINT_X_Y_Z_M","", "", arcpy.SpatialReference("WGS 1984"))
##fields=['POINT_X','POINT_Y'] #Change to match your column names containing x and y coordinates
##
##with arcpy.da.UpdateCursor(lyr,['SHAPE@X','SHAPE@Y']+fields) as cursor:
## for row in cursor:
## if None in row:
## row[0] = float(row[2])
## row[1] = float(row[3])
## cursor.updateRow(row)
I tried an updatecursor but get the following error.
row[0]=float(row[2])
TypeError: float() argument must be a string or a number, not 'NoneType'