AnsweredAssumed Answered

Buffer not added to map

Question asked by recurvata on Mar 28, 2012
Latest reply on Mar 28, 2012 by recurvata
When creating a buffer in a script, isn't it supposed to be added to the map by default? The code below creates the buffer just fine, but I have to add it to the map manually. Neither refreshing via code or with F5 or View - Refresh helps. I think this is the reason setting update_layer in the try block doesn't work. I know it's update_layer throwing the error because when I included it in the error message, that threw an error stating update_layer was undefined. Code & error below. Thanks for any ideas.

Code:
 import arcpy from arcpy import env  env.workspace = r"\\TestServer\TestCases_Geodatabase.gdb" mxd = arcpy.mapping.MapDocument("CURRENT")  df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]  case_number = arcpy.GetParameterAsText(0) #------------------------------------------------------------------------------- # Buffer Processing # def CreateBuffer():     # set buffer parameters     case = "Cases"     output ="Buffer_200"     dist = "200 feet"     side = "OUTSIDE_ONLY"       # delete existing temporary buffer, if any     if arcpy.Exists(output):         arcpy.Delete_management(output)      # create buffer     arcpy.Buffer_analysis(case, output, dist, side)      # update symbology     try:         source_layer = r"\\TestServer\Map Templates\GIS_Lyr_Files\Buffer.lyr"         update_layer = arcpy.mapping.ListLayers(mxd, "B*", df)[0]         arcpy.mapping.UpdateLayer(df, update_layer, source_layer, True)     except Exception as e:         arcpy.AddError("Updating symbology \n sl = " + source_layer + "\n" + e.message)  def main():     CreateBuffer()      arcpy.RefreshTOC     arcpy.RefreshActiveView  if __name__ == '__main__':     main()


Error:
Updating symbology   sl = \\TestServer\Map Templates\GIS_Lyr_Files\Buffer.lyr list index out of range Completed script Buffer200... Failed to execute (Buffer200). Failed at Wed Mar 28 08:22:06 2012 (Elapsed Time: 56.00 seconds)

Outcomes