I'm trying to import a batch .mxds into ArcPro projects and have run into a NameError I can't figure out.
I need the script to walk some folders, import .mxds one at a time, remove some layers, add some layers, change some layers and then save a copy of each ArcPro project. Last week the script ran just fine in ArcPro 2.7. I updated to ArcPro 2.8 and the script was broken. I had IT do a clean reinstall of ArcPro but no joy.
The script is longish but it's a just a bunch of simple code strung together. The relevant part is:
aprx = arcpy.mp.ArcGISProject(r" path to blank .aprx ")
aprx.importDocument( .mxd path grabbed from folder walk )
for m in aprx.listMaps():
if m.name == "Layers":
print("Adding: {0}".format(addlyr))
print("Adding: {0}".format(addlyr2))
m.addDataFromPath(addlyr)
m.addDataFromPath(addlyr2)
for lyr in m.listLayers():
if lyr.name == "Graphics Layer":
m.removeLayer(lyr)I have a long string of elif statements after this one. It errors on this first one, but if I remove it the error triggers on the next one and so on.
This is the error message I get:
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 90, in _get
return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name))
AttributeError
During handling of the above exception, another exception occurred:
File: " my script " line 52, in <module>
Traceback (most recent call last):
if lyr.name == "Graphics Layer":
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 96, in _get
(attr_name, self.__class__.__name__))
NameError: The attribute 'name' is not supported on this instance of Layer.
I've tried this in a separate script running from PyCharm and in an ArcPro notebook. Same error every time.
Has anybody else seen this?