What determines whether an arcpy map layer that was created as part of a created created using ...
result = arcpy.mp.ConvertWebMapToArcGISProject(WEB_MAP_AS_JSON)
can be turned off? I'm creating a map from the above...
aprx = result.ArcGISProject mymap = aprx.listMaps()
But when I try turn layers invisible, I get this for some:
The attribute 'visible' is not supported on this instance of Layer.
The layers all derive from a Portal webmap so that they have...
layer.isWebLayer = True
Most of my layers don't have that issue and wilingly switch to :
layer.visible = False >> Success
Is this limitation based on a setting in the webmap or in the underlying map services (item) ? Thanks.
So to refine my approach after re-reading the documentation on layer properties and methods, I try this:
# ... while iterating over layers print("Layer Name: "+layer.name) print("Layer visible: ",layer.visible) print("Layer supports 'visible': ",layer.supports("visible")) if layer.supports("visible"): try: layer.visible = !layer.visible print("Switched Layer visibility") except Exception as e: print("Unable to switch visibility") print(e) print("Layer visible: ",layer.visible)
On most cases, there result is as expected:
Layer Name: My Well Behaved Layer Layer visible: True Layer supports 'visible': True Switched Layer visibility Layer visible: False
But in other cases, I get this:
Layer Name: My Poorly Behaved Layer Layer visible: True Layer supports 'visible': True Unable to switch visibility The attribute 'visible' is not supported on this instance of Layer. Layer visible: True
It seems that it the layer says it supports 'visible', it should do so. Would love to know how to make sense of this.
layervisible !layer visible
is that =! a formatting or copy issue? (ie space between =, ! and lack of space between ! and layer...
A shortcut perhaps, but
case = not case # ie. layer.visible = not layer.visible
is a little less prone to format issues and misinterpretation
Sorry ,,, never a good idea to tweak things in transition from IDE to Geonet... I'm flipping the attribute to its Boolean opposite, so it should read:
layervisible not layer visible
If it was visible to begin with, I want to hide it, and the other around. Any idea why this would fail for some layers? Thanks, Dan.
Arne GelfertI don't know offhand since I am usually working with data I create myself... so everything is perfect of course .
If you get a list of layers that don't work, you may be able to determine some communalities between them... assuming that there isn't some random or obscure bug.
So I'm stumped on this one. I've gone ahead and republished my map service in question here, and now I'm seeing even weirder behavior. But since it doesn't merely relate to the 'visible' property, I'll start a new thread. Thanks for chiming in, Dan.