AnsweredAssumed Answered

adding layer twice

Question asked by wtgeographer on Apr 2, 2014
Latest reply on Apr 4, 2014 by wtgeographer
I am not sure why layers are being added twice here?

import arcpy from arcpy import env import pythonaddins  class ButtonClass1(object):     """Implementation for add_Layers_addin.button (Button)"""     def __init__(self):         self.enabled = True         self.checked = False     def onClick(self):         #set the map document reference         mxd = arcpy.mapping.MapDocument("CURRENT")          #set the dataframe reference using the map document and the first data frame in the list         df = arcpy.mapping.ListDataFrames(mxd)[0]          #set the layer reference using the map document reference and the first layer in the list of layers         layer1 = arcpy.mapping.ListLayers(mxd)[0]          symbologyLayer = r'G:\Texas\Potter-Randall\Database\Ownership.lyr'          #create a search cursor to get relevant information about a parcel         sc = arcpy.SearchCursor(layer1)          #for loop to get the selected data         for row in sc:             #select the relevant fields to be put on the map             ap = row.getValue("MAP_NUMBER")             addLayer = arcpy.mapping.Layer(r'G:\Texas\Potter-Randall\Database' + '\\' + str(ap) + '\\' + str(ap) + ".gdb" + '\\' + str(ap))             arcpy.ApplySymbologyFromLayer_management (addLayer, symbologyLayer)             arcpy.mapping.AddLayer(df, addLayer, "TOP")          #zoom to selected features         df.zoomToSelectedFeatures()         #refresh the active view         arcpy.RefreshActiveView()          #delete map, layer and dataframe variables         del mxd         del layer         del df         del ap         del sc         del row