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
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
Solved! Go to Solution.
with arcpy.da.SearchCursor(fc, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor
def onMouseDownMap(self, x, y, button, shift): arcpy.env.workspace = r"C:\temp\test.mdb" fc = "Point" list = [] with arcpy.da.SearchCursor(fc, ["Address_ID"]) as cursor: for row in cursor: list.append(row[0]) del cursor list.sort() Address_ID = list[-1] + 1 row_values = [(x, y, (x, y), Address_ID)] cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESS_ID"]) for row in row_values: cursor.insertRow(row) del cursor arcpy.RefreshActiveView()
def onMouseDownMap(self, x, y, button, shift): 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() fc = "points" arcpy.env.workspace = r"C:\Temp\test.mdb" list = [] with arcpy.da.SearchCursor(fc, ["Address_ID"]) as cursor: for row in cursor: list.append(row[0]) del cursor list.sort() Address_ID = list[-1] + 1 row_values = [(x, y, (x, y), Address_ID)] cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESS_ID"]) for row in row_values: cursor.insertRow(row) del cursor arcpy.RefreshActiveView() # Stop the edit operation. edit.stopOperation() # Stop the edit session and save the changes edit.stopEditing(True) pass
Traceback (most recent call last): File "C:\Users\talmeida\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{BB229966-100D-4482-A3FE-B298BD262597}\AddPoints_addin.py", line 30, in onMouseDownMap for row in cursor: RuntimeError: Too few parameters. Expected 1.
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): arcpy.env.overwriteOutput = True # Start an edit session. Must provide the worksapce. edit = arcpy.da.Editor(env.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() fc = "points" arcpy.env.workspace = r"C:\Temp\test.mdb" list = [] with arcpy.da.SearchCursor(fc, ["Address_ID"]) as cursor: for row in cursor: list.append(row[0]) del cursor list.sort() Address_ID = list[-1] + 1 row_values = [(x, y, (x, y), Address_ID)] cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESS_ID"]) for row in row_values: cursor.insertRow(row) del cursor # Stop the edit operation. edit.stopOperation() # Stop the edit session and save the changes edit.stopEditing(True) arcpy.RefreshActiveView() pass
Traceback (most recent call last): File "C:\Users\talmeida\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{BB229966-100D-4482-A3FE-B298BD262597}\AddPoints_addin.py", line 36, in onMouseDownMap AddressID = list[-1] + 1 TypeError: coercing to Unicode: need string or buffer, int found
AddressID = list[-1] + 1
AddressID = int(list[-1].strip('CC0')) + 1 AddressID = 'CC0' + str(AddressID)