AddGeometryAttributes_management failing to execute

700
5
06-12-2019 11:42 AM
AndrewVanWie
New Contributor

I'm having a problem where I'm trying to calculate area of geometry but it is failing in my Python script. Using ArcGIS 10.6.1.

arcpy.AddGeometryAttributes_management("layername", "AREA", Area_Unit="SQUARE_KILOMETERS") 
Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\AddGeometryAttributes.py", line 292, in <module>
    AddGeometryAttributes(fc, geomProperties, lUnit, aUnit, cs)
  File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\AddGeometryAttributes.py", line 49, in AddGeometryAttributes
    fields = CreateOutputFields(fc, geomProperties, hasZ, hasM)
  File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\AddGeometryAttributes.py", line 232, in CreateOutputFields
    currentFields = [field.name for field in arcpy.ListFields(fc)]
TypeError: 'geoprocessing list object' object is not iterable
 
Failed to execute (AddGeometryAttributes).

Any ideas? 

0 Kudos
5 Replies
JoshuaBixby
MVP Esteemed Contributor

sharing with Python‌ since this is an ArcPy question and not ArcGIS API for Python question.  Also, Andrew VanWie‌, please change this to a question instead of a discussion.

0 Kudos
RandyBurton
MVP Regular Contributor

Can you share a bit more of your script - specifically, where the layer name is being set?

0 Kudos
AndrewVanWie
New Contributor

Pardon my newbie-ness with Python. Hope this makes sense. Not sure how to change my post from Discussion to Question.

I have 8 workstations and users running ArcGIS 10.6. I get the error on only 2 workstations, it works well on the other 6, so that is my confusion. The workstations should be set up identically.

After selecting a feature from the "blocks" layer in ArcMap, I run an executable script in the ArcMap Python window that requires parameters for "blockname" and "point density" to scatter random points in polygons at specified density: 

import sys
sys.argv = ["path_to_script.py", "NXXWXXX", "####"]
execfile( "path_to_script.py" )

Then, in my main script "path_to_script.py" I set the layername with sys.argv[1] and sys.argv[2]. Processing is done from source data paths for imagery and features, running arcpy scripts. All layer processing is output to a temporary geodatabase workspace, which is removed at the end. I removed the remaining processing arcpy lines following arcpy.AddGeometryAttributes_management for sake of space since this is where it fails. Everything works right up to it.

import arcpy
import tempfile
def main ( ):
   blockname = sys.argv[1]
   point_density = sys.argv[2]
   arcpy.CreateFileGDB_management(tempfile.gettempdir(), blockname + "_" + point_density)
   arcpy.CreateFeatureDataset_management(tempfile.gettempdir() + "/" + blockname + "_" + point_density + ".gdb", "dataset1", "WGS 1984 UTM Zone 17N.prj")
   arcpy.env.workspace = tempfile.gettempdir() + "/" + blockname + "_" + point_density + ".gdb" 
   try:
    arcpy.MakeFeatureLayer_management ("blocks", blockname + "_Layer")
    arcpy.Clip_management(polygon_features_path, "#", blockname + "_clip", blockname + "_Layer", "#", "ClippingGeometry")
    arcpy.Clip_analysis(feature_buffers_path, blockname + "_Layer", blockname + "_buffers")
    arcpy.RasterToPolygon_conversion(blockname + "_clip", "dataset1/" + blockname + "_rast2poly", "NO_SIMPLIFY")
    qry = '"gridcode" > 35'
    flayer = arcpy.MakeFeatureLayer_management (blockname + "_rast2poly", blockname + "_rast2poly2_Layer")
    arcpy.SelectLayerByAttribute_management (flayer, "NEW_SELECTION", qry)
    arcpy.CopyFeatures_management (flayer, "dataset1/" + blockname + "_export")
    arcpy.Dissolve_management (blockname + "_export", "dataset1/" + blockname + "_dissolve")
    arcpy.AddGeometryAttributes_management(blockname + "_dissolve", "AREA", Area_Unit="SQUARE_KILOMETERS")
...
...
...
if __name__ == '__main__':
   main() 

					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
RandyBurton
MVP Regular Contributor

With only a quick look, I see you are sometimes using "dataset1/" + ... and sometimes not using it.  I wonder if the inconsistency is the issue.  You might try:

arcpy.CopyFeatures_management (flayer, "dataset1/" + blockname + "_export")
arcpy.Dissolve_management ("dataset1/" + blockname + "_export", "dataset1/" + blockname + "_dissolve")
arcpy.AddGeometryAttributes_management("dataset1/" + blockname + "_dissolve", "AREA", Area_Unit="SQUARE_KILOMETERS")‍‍‍‍
0 Kudos
AndrewVanWie
New Contributor

Upgrading to ArcGIS Desktop 10.7.1 somehow fixed the issue on the 2 workstations that were affected. I'm not sure what was going on with 10.6.

0 Kudos