Thanks for both of your replies Brad.I've come up with the following modified function based on code found in the link you gave. However, as I'm working on a distributed geoprocessing tool I still have two problems with my current solution:1) I'm guessing the registry keys change for each release? i.e. the typelib key in the example given for 10 from the link (for the esriFramework OLB) was actually the key for esriGlobeCore.Globe on my install (9.3.1).2) This approach will only work for Windows.def refreshArcMap():
"""
Refreshes view in current ArcMap session.
Assumptions: Python comtypes framework installed & comtypes.client already imported
Limitations: Only works on Windows & only tested for ArcGIS 9.3.1 (32-bit).
"""
try:
import _winreg
# Look in registry for the TypeLib entry for the esriFramework OLB
keyESRI = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, \
r"TypeLib\{866AE5D3-530C-11D2-A2BD-0000F8774FB5}\1.0\HELPDIR")
# Get path of ArcGIS type libraries as string from registry e.g "C:\Program Files\ArcGIS\com"
comDir =_winreg.QueryValueEx(keyESRI, None)[0]
# Load the required COM libraries
esriFramework = comtypes.client.GetModule(comDir + r'\esriFramework.olb')
esriArcMapUI = comtypes.client.GetModule(comDir + r'\esriArcMapUI.olb')
# Get the current ArcMap session & refresh view
objApplication = comtypes.client.CreateObject(esriFramework.AppRef, interface=esriFramework.IApplication)
objMxDocument = objApplication.Document.QueryInterface(esriArcMapUI.IMxDocument)
objMxDocument.ActiveView.Refresh()
gp.AddMessage("View refreshed...")
except Exception, ErrorDesc:
# If an error occurred while refreshing instruct user to manually refresh
gp.AddWarning("A problem occured when trying to automatically refresh ArcMap!")
gp.AddWarning("Perform a manual refresh of map window (i.e. click 'Refresh View' button at the bottom of the map window) to view results")