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":
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?
... View more
It does load properly when done manually. Seeing your repost of that code made me think to try to load a single feature class into an empty mxd, which worked. It took a few hours, but I finally figured out the problem had to do with the fact that I was trying to create the layer in the mxd to have the same name as the feature class in the gdb. Each feature class is named <some county>_Anno_Ins and when I changed this line in my script: temp = County_Nam + "_Anno_Ins" to temp = County_Nam + "_DPatterson" they were added to the mxd's properly as annotation. So problem solved. Thanks for the help.
... View more
I've created annotation feature classes from Microstation DGN files and I need to add those to a series of mxd's using arcpy. I've been able to do that, but the layers are added as polygon features not as annotation features. I've dug around and found this solutionAnnotation classes not visible after adding an annotation layer , but it doesn't work for me. The feature class still adds as a polygon layer. Has anyone else run into this? Below is the relevant code. for df in arcpy . mapping . ListDataFrames ( mxd ) : print df . name if df . name == "Layers" : featclasses = arcpy . ListFeatureClasses ( "" , "" , County_Nam ) print featclasses for fc in featclasses : print fc addLayer = arcpy . mapping . Layer ( fc ) reflayer = arcpy . mapping . ListLayers ( mxd , "Private" , df ) [ 0 ] if fc == County_Nam + "_Anno_Ins" : print fc temp = County_Nam + "_Anno_Ins" arcpy . MakeFeatureLayer_management ( fc , temp ) annoLayer = arcpy . mapping . Layer ( temp ) arcpy . mapping . AddLayer ( df , annoLayer , "BOTTOM" )
... View more