laptop and a wrench

Bug

Recreating the geoprocessor object using Dispatch causes a script to fail if the geoprocessor has already been created.

Last Published: August 25, 2014 No Product Found
Bug ID Number NIM004537
SubmittedSeptember 30, 2006
Last ModifiedJune 5, 2024
Applies toNo Product Found
Version found9.2
Version Fixed9.3
StatusFixed

Description

** This bug has been fixed at ArcGIS 9.2 Service Pack 2. Download ArcGIS 9.2 Service Pack 2 from the link in the Related Information section below. **

As long as Python is installed properly and the Windows file associations are set properly, there should be no problems running win32com scripts from within ArcToolBox.

There is, however, a known bug that causes win32com scripts to work only once from PythonWin.

Cause

This is a known issue with version 9.2 final and 9.2 Service Pack 1. This issue has been resolved at 9.2 SP2.

Workaround

Download and install ArcGIS 9.2 Service Pack 2.

Use the following workaround if using version 9.2 final or 9.2 Service Pack 1.

Scripts that use win32com require PythonWin, regardless of whether the scripts are being run from ArcToolBox, IDLE or PythonWin. This is because the win32com module is part of PythonWin. To run or edit scripts that use the win32com module, PythonWin needs to be installed as well as implementing one of the following workarounds.

  • Delete the geoprocessor at the end of the script. For example, see the following simple Python script:

    Code:
    # Import system modules
    import sys, string, os, win32com.client

    # Create the Geoprocessor object
    gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

    gp.overwriteoutput = 1

    # Load required toolboxes...
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

    # Local variables...
    cities_Buffer1_shp = "C:\\ESRI\\ESRIDATA\\CANADA\\cities_Buffer1.shp"
    cities_shp = "C:\\ESRI\\ESRIDATA\\CANADA\\cities.shp"

    # Process: Buffer...
    gp.Buffer_analysis(cities_shp, cities_Buffer1_shp, "1 DecimalDegrees",
    "FULL", "ROUND", "NONE", "")

    print "done"

    Add the following line to the end of the script:

    Code:
    del gp

    Do this for all scripts that use the win32com client to be edited or run from PythonWin or IDLE.
  • Convert the script to use the new arcgisscripting module available at 9.2. It does not need to delete the gp object after the execution of each Python script. This is a better workaround because performance is improved when the gp is reused. For example, this is the the above script converted to use the arcgisscripting module:

    Code:
    # Import system modules
    import sys, string, os, arcgisscripting

    # Create the Geoprocessor object
    gp = arcgisscripting.create()

    gp.overwriteoutput = 1

    # Load required toolboxes...
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

    # Local variables...
    cities_Buffer1_shp = "C:\\ESRI\\ESRIDATA\\CANADA\\cities_Buffer1.shp"
    cities_shp = "C:\\ESRI\\ESRIDATA\\CANADA\\cities.shp"

    # Process: Buffer...
    gp.Buffer_analysis(cities_shp, cities_Buffer1_shp, "1 DecimalDegrees",
    "FULL", "ROUND", "NONE", "")

    print "done"

Steps to Reproduce

Bug ID: NIM004537

Software:

  • No Product Found

Get notified when the status of a bug changes

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options