listLayer randomly can't find any names

251
1
04-07-2023 05:14 AM
AnonymousUser23
New Contributor III

 

                        lyrList = map.listLayers()
                        for lyr in lyrList:
                            if  lyr.supports("NAME"):
                                if "Hillshade" in lyr.name or lyr.name == "temp":
                                    map.removeLayer(lyr)
                                # if lyr.name == "Lift Stations":
                                #     insertrows(map, lyr, ski_run_query_lyr)
                                #     insertrows(map, "ski_run_query", lift_query_lyr)
                                if  lyr.name =="Building Centroid":
                                    insertrows(map, resort_feature_query_lyr)
                                    insertrows(map, resort_feature_resort_lyr)
                                    insertrows(map, building_lyr)
                                    insertrows(map, building_other_lyr)

 

Screenshot 2023-04-07 at 7.08.50 AM.pngThe first run of my script every time comes up with attribute "name" not supported on the layers. They make it through the name check but then fail. Has anyone else seen this. 

Tags (3)
0 Kudos
1 Reply
DavidPike
MVP Frequent Contributor

It seems like supports() is giving a false positive.  I would try and catch the specific layer causing the issue in a try except block initially as that might help you figure out the cause.
I'd also avoid using map as an object name as it could cause confusion, but that's just my opinion. 

0 Kudos