Select to view content in your preferred language

ArcGIS Pro | ArcPy - How To Refresh the Map

31379
30
02-16-2017 06:15 PM
TD
by
Occasional Contributor

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

  • Windows 8.1
  • ArcGIS Pro 1.4.1

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')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
30 Replies
RyanBoyd
New Contributor

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.

0 Kudos