Refresh Layer After Adding Field

798
2
Jump to solution
02-06-2012 06:44 AM
BRIANRITTER
New Contributor II
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
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BRIANRITTER
New Contributor II
I am not sure why it made a difference but I changed my variable path to r"\\......" and removed the slashes that were not needed using r, and it started working.

View solution in original post

0 Kudos
2 Replies
BRIANRITTER
New Contributor II
I am not sure why it made a difference but I changed my variable path to r"\\......" and removed the slashes that were not needed using r, and it started working.
0 Kudos
TonyAlmeida
Occasional Contributor II
Could you post your tools parameters values for this tool please?

Thanks.
0 Kudos