for lyr in updateMap.listLayers():
if lyr.supports("DATASOURCE"):
arcpy.AddMessage(lyr.dataSource)
A script opens an ArcGIS Pro project file, goes through the list of layers within a map, checks to see if each layer supports the 'DataSource' property before giving me a message with that datasource
The script fails as it reaches a layer which doesn't support the 'DataSource' property....
NameError: The attribute 'dataSource' is not supported on this instance of Layer.
Can someone explain this non-sensical behaviour to me?
ArcGIS Pro 2.8.2
I have no idea why this happens, but to not let it fail your script, you can do it in a try-catch block:
for lyr in updateMap.listLayers():
try:
arcpy.AddMessage(lyr.dataSource)
except NameError:
pass
from Layer—ArcGIS Pro | Documentation
could it be your layer source?
dataSource (Read Only) | Returns the complete path for the layer's data source. It includes the full workspace path and name of the dataset. For enterprise geodatabase layers, a string containing the layer's connection information is returned. Tip:Enterprise geodatabase layers in an ArcGIS Pro project do not retain the path to the database connection file (.sde) that was used to create the layer.
| Strin |
Possible (and I'll check) but not likely as all the layers that I check (using a query on the list layers) are in the same location (default.gdb)...but even then, the whole point of 'supports' is that this type of error doesn't occur.