GraphicElement Visibility

557
3
05-12-2017 01:19 PM
DevinUnderwood2
Occasional Contributor
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
# The text element is a textbox
elm1 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "closeup1")[0]

if mxd.dataDrivenPages.currentPageID == 1:
 elm1.visible == True
elif elm1 != 1:
 elm.visible == False

if mxd.dataDrivenPages.currentPageID == 1:
 print "yes"
elif mxd.dataDrivenPages.currentPageID <> 1:
 print "no"
‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Anyone familiar with Graphic Element Visibility property. It doesn't work for me.

I used the print statements to verify current page which is working fine.

I referenced http://pro.arcgis.com/en/pro-app/arcpy/mapping/graphicelement-class.htm

and there isn't a good example.

0 Kudos
3 Replies
DanPatterson_Retired
MVP Esteemed Contributor
elm1.visible == True   # this is an equality check... ie. is it visible????
elm1.visible = True    # this is an assignment statement.  ie. make it visible...
# choose wisely a '=' makes a huge difference‍‍‍‍‍‍
0 Kudos
DevinUnderwood2
Occasional Contributor

Right, good catch. I am checking whether elm1(text element) appears while viewing page 1.

If so, make visible.

I changed it but still no luck.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
if mxd.dataDrivenPages.currentPageID == 1
    elm1.visible = True
else:
    elm.visible = False

if elm1 != 1:
   # do something
else:
   # do something else

your previous lines don't account for the possible combinations.  ie they are separate questions and you are trying to do shortcuts.   So if the current page id isn't 1... set elem1 visible... else, turn it off.

Now if elm1 is not = 1 (don't even know if that is correct) do something, otherwise do something else

0 Kudos