AnsweredAssumed Answered

arcpy.da.InsertCursor help please

Question asked by Tonyalmeida on Feb 10, 2014
Latest reply on Feb 12, 2014 by Tonyalmeida
I am trying to create a script that will create a new point feature to a point feature class, but also add the x, y coordinets to "X_Coord" and "Y_Coord" fields. The following code sort of works but only populates the "X_Coord" field. I can't seem to get it to populate the "Y_Coord" field.

works but only populates the "X_Coord" field.
import arcpy import pythonaddins import os from arcpy import env  class Add_points(object):     """Implementation for AddPoints_addin.Add_points (Tool)"""     def __init__(self):         self.enabled = True         self.cursor = 3 # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.     def onMouseDownMap(self, x, y, button, shift):         fc = "points"         workspace = r"C:\Temp\test.mdb"         arcpy.env.overwriteOutput = True          # Start an edit session. Must provide the worksapce.         edit = arcpy.da.Editor(workspace)          # Edit session is started without an undo/redo stack for versioned data         #  (for second argument, use False for unversioned data)         edit.startEditing(True)          # Start an edit operation         edit.startOperation()                  mxd = arcpy.mapping.MapDocument("Current")         df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]         lyr = arcpy.mapping.ListLayers(mxd, "points")[0]          #message = "Your mouse clicked:" + str(x) + ", " + str(y)         #pythonaddins.MessageBox(message, "My Coordinates")                           point = arcpy.Point(x, y)         pointGeometry = arcpy.PointGeometry(point)         row_value = ((x, y))         cursor = arcpy.da.InsertCursor(fc, ("X_Coord", "SHAPE@XY"))         cursor.insertRow(row_value)         """ Create a copy of the PointGeometry objects, by using pointGeometry  """         """  as input to the CopyFeatures tool. """         arcpy.CopyFeatures_management(pointGeometry, r"C:\Temp\test.mdb")          # Stop the edit operation.         edit.stopOperation()          # Stop the edit session and save the changes         edit.stopEditing(True)           arcpy.RefreshActiveView()         pass      



I have tried the following but nothing happens, no point feature is created and the "X_Coord" and "Y_Coord" fields are not populated.
import arcpy import pythonaddins import os from arcpy import env  class Add_points(object):     """Implementation for AddPoints_addin.Add_points (Tool)"""     def __init__(self):         self.enabled = True         self.cursor = 3 # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.     def onMouseDownMap(self, x, y, button, shift):         fc = "points"         workspace = r"C:\Temp\test.mdb"         arcpy.env.overwriteOutput = True          # Start an edit session. Must provide the worksapce.         edit = arcpy.da.Editor(workspace)          # Edit session is started without an undo/redo stack for versioned data         #  (for second argument, use False for unversioned data)         edit.startEditing(True)          # Start an edit operation         edit.startOperation()                  mxd = arcpy.mapping.MapDocument("Current")         df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]         lyr = arcpy.mapping.ListLayers(mxd, "points")[0]          #message = "Your mouse clicked:" + str(x) + ", " + str(y)         #pythonaddins.MessageBox(message, "My Coordinates")          Fields = ["X_Coord", "Y_Coord", "SHAPE@XY"]                          point = arcpy.Point(x, y)         pointGeometry = arcpy.PointGeometry(point)         row_value = ((x, y))         cursor = arcpy.da.InsertCursor(fc, (Fields))         cursor.insertRow(row_value)         """ Create a copy of the PointGeometry objects, by using pointGeometry  """         """  as input to the CopyFeatures tool. """         arcpy.CopyFeatures_management(pointGeometry, r"C:\Temp\test.mdb")          # Stop the edit operation.         edit.stopOperation()          # Stop the edit session and save the changes         edit.stopEditing(True)           arcpy.RefreshActiveView()         pass 


and if possible i would like it to populate an auto sequential number based on the last highest number. The field i need the sequential number is a field called the Address_ID field.

Outcomes