Hi ArcGIS Community,
I have a Python script that simply add points to a feature class in file GDB every second. The corresponding layer is in an ArcGIS Pro map, and I would like to visualise the point as their are being added, without manually interacting with the map.
When running the script as a standalone script, panning or zooming will force the map to refresh and display points newly added.
How can I programatically refresh the map to see the update displayed dynamically, without the need for user interaction ?
Thanks
import arcpy, time, random, datetime
aprx = arcpy.mp.ArcGISProject('D:\workspaces\sandbox\sandbox\sandbox.aprx')
fields = ['SHAPE@XY', 'DATETIME']
iteration = 10
second = 1
# bouding box: east, west, south, north (define your own extent)
boundingBox = [x1,x2,y1,y2]
fc = r"D:\workspace\mygdb.gdb\Points"
for i in range(iteration):
x = random.uniform(boundingBox[0],boundingBox[1])
y = random.uniform(boundingBox[2],boundingBox[3])
xy = (x,y)
cursor = arcpy.da.InsertCursor(fc, fields)
cursor.insertRow((xy, datetime.datetime.now()))
del cursor
print('Done! ... i=' + str(i))
time.sleep(second)
print('QUIT')
I'm not sure if there is anything official, but a "hack" that worked for me was to add a CalculateField and populate any field in any row with the value that is already there. This seems to trigger a refresh and works for egdb and file gdb.