I'm trying to change feature layer visibility ranges with Arcpy in ArcPro but am running into issues. For some reason all of the layers don't support scale ranges despite them being feature layers in the TOC. I can change the visibility ranges manually in Pro. The code below runs with no errors, but none of the visibility ranges change.
This is what is printed after running the code...
What am I doing wrong? How can I make this happen?
Solved! Go to Solution.
have you tried without the try except block? I'm not sure of a layer property VISIBLESCALE so that may be forcing it into the except. Your error message may be misleading by that logic.
Is this ArcMap or Pro? it might be min and maxThreshold properties now.
have you tried without the try except block? I'm not sure of a layer property VISIBLESCALE so that may be forcing it into the except. Your error message may be misleading by that logic.
Is this ArcMap or Pro? it might be min and maxThreshold properties now.
Removing lyr.supports("VISIBLESCALE") and switching minScale and maxScale to minThreshold and maxThreshold was the fix! ESRI Documentation
Here's the working code:
Thanks @DavidPike!
Screenshots of code are pretty much useless unless the issue is really obvious and the code is short. Please post code as text in future.
Yeah, I was originally going to but it started giving me trouble about it being HTML so I resorted to screenshots.
Thanks for the link though.
Here's the working code snippet:
def set_visibility_range(lyr, min_threshold, max_threshold):
if lyr.isFeatureLayer:
lyr.visible = True
lyr.minThreshold = min_threshold
lyr.maxThreshold = max_threshold
else:
print(f"'{lyr.name}' does not support scale ranges")
for lyr in m.listLayers():
if "Primary" in lyr.name:
set_visibility_range(lyr, 300000, 0)
elif "Secondary" in lyr.name:
set_visibility_range(lyr, 2500, 0)
elif "Pole" in lyr.name and "Anno" not in lyr.name:
set_visibility_range(lyr, 5000, 0)
elif "Anno" in lyr.name:
set_visibility_range(lyr, 2500, 0)
else:
set_visibility_range(lyr, 0, 0)
aprx.save()
print("FC visibility ranges set...")