AnsweredAssumed Answered

Refresh Layer After Adding Field

Question asked by HARMON on Feb 6, 2012
Latest reply on Aug 8, 2012 by Tonyalmeida
I have created a python script that adds and updates a field within an existing feature class added to ArcMap.  I have set the script to run as a tool in the map document.  The script executes fine adding/udating the field 'Acres' to the polygon_intersect feature class.  When opening the attribute table after the script runs the new field does not show.  I can open ArcCatalog and view the table and the field shows.  Does anyone know of a different way to refresh the feature class other than what my code is doing.  The refresh does not work and the only way to see the new field is to remove the feature class from the TOC and then add it back.  I have posted my code below.

 import arcpy from arcpy import env from arcpy import mapping  arcpy.env.overwriteOutput = True  # Set Local Variable  A = "\\\\Admingis\\E\\GISDATA\\Projects\\AG\\AgAssess.gdb\\polygon_intersect" mxd = arcpy.mapping.MapDocument("CURRENT")  # Create attribute called Acres  try:     if arcpy.Exists(A):         arcpy.AddField_management(A, "Acres", "DOUBLE")         print "Acres Attribute Added"      else:         print "Acres Field Not Added"           except arcpy.ExecuteError:     print "Error Occured Add Acres Attribute Failed"     print (arcpy.GetMessages(2))      # Create curser to update acres field  cur = arcpy.UpdateCursor(A)  # Pass through each row to update acres value  try:      if arcpy.Exists(A):          for row in cur:             row.Acres = row.Shape_Area /43560             cur.updateRow(row)             print "Acres Updated"      else:         print "Acres Not Updated Feature Class Does Not Exist"  except arcpy.ExecuteError:     print "Error Occured Update Failed"     print (arcpy.GetMessages(2))  del cur, row  arcpy.RefreshCatalog(A) arcpy.RefreshActiveView() arcpy.RefreshTOC()  # Delete cursor and objects  del arcpy, env, A, mxd 


Thanks,

Brian

Outcomes