Hi there,
I'm currently trying to call legend items from a layout element. However, on calling the .items attribute the following error is thrown:
<class 'arcpy._mp.LegendElement'>
'LegendElement' object has no attribute 'items'
List of attributes related to LegendElement:
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__from_scripting_arc_object__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_arc_object', 'elementHeight', 'elementPositionX', 'elementPositionY', 'elementRotation', 'elementWidth', 'mapFrame', 'name', 'showTitle', 'syncLayerOrder', 'syncLayerVisibility', 'syncNewLayer', 'syncReferenceScale', 'title', 'type', 'visible']
Example code:
legend = fepExportTemplate.listElements('LEGEND_ELEMENT')[0]
print(type(legend)) # returns LegendElement
print(str(legend.items)) # produces error
Testing this on a different machine with a copy of the data allowed the .items attribute to show up fine. Beacause of this I tried running the arcpy.getInstallInfo() method to compare the two environments. The main difference that I can see is the different are the ArcGIS Pro versions, but apparently updating the version of ArcGIS Pro used by ArcServer is not an option. See below for the differences between the two.
Original data (.items attribute doesn't work)
{'LicenseLevel': 'Advanced', 'Installer': 'gisadmin', 'ProductName': 'Server', 'Version': '10.8.1', 'SourceDir': 'D:\\_geoworx\\unpack\\ArcGIS 10.8.1\\ArcGISServer\\SetupFiles\\', 'InstallType': 'N/A', 'BuildNumber': '24234', 'InstallDate': '08/08/2020', 'InstallTime': '14:35:52', 'SPNumber': 'N/A', 'SPBuild': 'N/A', 'ProVersion': '2.6.0'}
Copied data on separate computer (.items attribute works)
{'LicenseLevel': 'Advanced', 'Installer': 'AngusHunt', 'ProductName': 'ArcGISPro', 'Version': '2.8', 'SourceDir': 'C:\\Users\\AngusHunt\\Documents\\ArcGIS Pro 2.8\\ArcGISPro\\', 'InstallType': 'N/A', 'BuildNumber': '29751', 'InstallDate': '21/05/2021', 'InstallTime': '13:34:22', 'SPNumber': 'N/A', 'SPBuild': 'N/A'}
Any ideas would be very helpful.
Solved! Go to Solution.
Different versions of arcpy.
Pro's LegendElement—ArcGIS Pro | Documentation
items is a readonly property
and in CIM LegendElement—ArcGIS Pro | Documentation
Different versions of arcpy.
Pro's LegendElement—ArcGIS Pro | Documentation
items is a readonly property
and in CIM LegendElement—ArcGIS Pro | Documentation
Thanks Dan, that makes sense. Do you know if it is possible to update the Arcpy packages on an ArcGIS Server?
Don't know Angus, not a server user, but I was under the impression that server had python 2 and python 3 variants. python 3 is what Pro uses, so check your server documentation.