I am trying to write a standalone script for ArcGIS Pro, so that it checks if a layer is visible in the table of contents before running any geo processing functions. I have tried using the following, but it ends up just printing all of the layers in the TOC even if they are turned off, and I get an error stating:
"AttributeError: The attribute 'visible' is not supported on this instance of Layer."
I have tried running it in the Python Window within ArcPro as well, with same result.
# Import ArcPy site-package
import arcpy
# the open records request Pro Project
aprx = arcpy.mp.ArcGISProject(
r"\\san_marcos\arcfile\Department Projects and File Geodatabases\Public Services\Transportation\GSipes\ProProjects\OpenRecordsRequests\OpenRecordsRequests.aprx")
# list of layers in the project
myMap = aprx.listMaps()[0]
for layer in myMap.listLayers():
if layer.supports("VISIBLE") == True:
if layer.visible == True:
print(layer.name)
print('I am done listing layers')