import arcgisscripting
gp = arcgisscripting.create()
strLayer = gp.GetParameterAsText(0)
strExpression = gp.GetParameterAsText(1)
gp.SelectLayerByAttribute_management(strLayer, "NEW_SELECTION", strExpression)
import comtypes.client
# Load the required COM libraries
esriFramework = comtypes.client.GetModule(r'C:\Program Files\ArcGIS\com\esriFramework.olb')
esriArcMapUI = comtypes.client.GetModule(r'C:\Program Files\ArcGIS\com\esriArcMapUI.olb')
# Create the AppROT object which contains all open ArcGIS applications
objAppROT = comtypes.client.CreateObject(esriFramework.AppROT, interface=esriFramework.IAppROT)
# Loop through each open ArcGIS application
for i in range(objAppROT.Count):
# Query interface (convert) the current item in the list to something we can work with.
objApplication = objAppROT.Item(i).QueryInterface(esriFramework.IApplication)
# Check to see if the current ArcGIS application is ArcMap.
if objApplication.Name == "ArcMap":
# Get the current document in the ArcMap application.
objMxDocument = objApplication.Document.QueryInterface(esriArcMapUI.IMxDocument)
# Refresh the active view.
objMxDocument.ActiveView.Refresh()
gp.addmessage("View refreshed...")
del objAppROT
import arcgisscripting
gp = arcgisscripting.create()
strLayer = gp.GetParameterAsText(0)
strExpression = gp.GetParameterAsText(1)
gp.SelectLayerByAttribute_management(strLayer, "NEW_SELECTION", strExpression)
import comtypes.client
# Load the required COM libraries
esriFramework = comtypes.client.GetModule(r'C:\Program Files\ArcGIS\com\esriFramework.olb')
esriArcMapUI = comtypes.client.GetModule(r'C:\Program Files\ArcGIS\com\esriArcMapUI.olb')
# Get the current ArcMap session
objApplication = comtypes.client.CreateObject(esriFramework.AppRef, interface=esriFramework.IApplication)
objMxDocument = objApplication.Document.QueryInterface(esriArcMapUI.IMxDocument)
objMxDocument.ActiveView.Refresh()
gp.addmessage("View refreshed...")
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")
Thanks for both of your replies Brad.
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.