import arcpy import pythonaddins class Toggle_Cust(object): """Implementation for C1_Cust.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): #Get the current Map Document and Create the Layer Index. mxd = arcpy.mapping.MapDocument("Current") COF_Customers = arcpy.mapping.ListLayers (mxd) [1] #Turn the Layer On or Off depending on property value if self.checked = True: COF_Customers.visible = True arcpy.RefreshActiveView() print "Customers On!" else: COF_Customers.visible = False arcpy.RefreshActiveView() print "Customers Off!"
import arcpy import pythonaddins class Toggle_Cust(object): """Implementation for C1_Cust.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): #Get the current Map Document and Create the Layer Index. mxd = arcpy.mapping.MapDocument("Current") lyrlist = arcpy.mapping.ListLayers (mxd) [0] #Identify the Customer Layer by Index Value COF_Customers = arcpy.mapping.ListLayers (mxd) [1] COF_Customers.visible = True arcpy.RefreshActiveView() print "Customers On!"
Solved! Go to Solution.
import arcpy import pythonaddins class Toggle_Cust(object): """Implementation for C1_Cust.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): #Get the current Map Document and Create the Layer Index. mxd = arcpy.mapping.MapDocument("Current") for lyr in arcpy.mapping.ListLayers (mxd): if lyr.name == "COF_Cust": if lyr.visible == False: lyr.visible = True arcpy.RefreshActiveView() elif lyr.visible == True: lyr.visible = False arcpy.RefreshActiveView() else: pass
if self.checked == True
for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == "your layer name": if self.checked == True: "your layer name".visible = True arcpy.RefreshActiveView() print "Customers On!" else: "your layer name".visible = False arcpy.RefreshActiveView() print "Customers Off!"
self.checked = False
layer.visible = not layer.visible self.checked = layer.visible
import arcpy import pythonaddins class Toggle_Cust(object): """Implementation for C1_Cust.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): #Get the current Map Document and Create the Layer Index. mxd = arcpy.mapping.MapDocument("Current") for lyr in arcpy.mapping.ListLayers (mxd): if lyr.name == "COF_Cust": if lyr.visible == False: lyr.visible = True arcpy.RefreshActiveView() elif lyr.visible == True: lyr.visible = False arcpy.RefreshActiveView() else: pass