Hi,
I am quite a beginner with Python, thus I will be grateful for your help . I want to create multiple points on my map. I managed to do that but unfortunately my attribute table is not updating (it is always only one row even I added multiple points). Could you take a look at my code at tell me where is the problem? For any help thank you so much!
class Obstacle(object):
"""Implementation for new_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.shape = "circle" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
def onMouseDown(self, x, y, button, shift):
pass
def onMouseDownMap(self, x, y, button, shift):
#workspace = r"\\\\abc\\home\\xxx\\Documents\\ArcGIS\\Default.gdb"
#adding points to the map
mxd = arcpy.mapping.MapDocument ("CURRENT")
sr = mxd.activeDataFrame.spatialReference
pntFc = r"\\abc\home\xxx\Documents\ArcGIS\treepoints"
pt = arcpy.Point()
pt.X = float(x)
pt.Y = float(y)
ptGeoms = [arcpy.Geometry ("POINT", pt, sr)]
if not arcpy.Exists (pntFc):
arcpy.CopyFeatures_management(ptGeoms, pntFc)
else:
with arcpy.da.InsertCursor (pntFc, "SHAPE@") as iCurs:
iCurs.insertRow (ptGeoms)
arcpy.RefreshActiveView ()
Best,
Paulina
In that case I can only assume your if statement is always triggering too, add a print statement to test this:
if not arcpy.Exists (pntFc): arcpy.CopyFeatures_management(ptGeom, pntFc) print "Deleting and replacing existing FC"
I added the print commend and it was printed
I cant tell you why, but you need to try work out why this script does not find the existing data:
pntFc = r"\\abc\home\xxx\Documents\ArcGIS\treepoints"
if not arcpy.Exists (pntFc):
print "I cant find the existing data"
Yes, I will need to figure it out . Anyway, thank you for your help and time!