Select to view content in your preferred language

Strange problem running GP tools from VBA

2751
5
06-10-2010 06:25 AM
MarkWhitling
Deactivated User
Hi there.

I have written a script that runs a GP tool (custom python script) from a CustomUI button in ArcGIS 9.3.1 (ArcView); windows 2000.

The problem is that the code runs absolutely perfectly!  on this machine...

I have tried moving everything to another PC (same set-up but Windows XP SP3); same folder paths; same ArcGIS install source even but the code does not run.  I get a run-time error '-2147467259 (80004005)' automation error unspecified error when it tries to run the GP tool..  The tool it's self does run when launched through ArcToolbox, even if using the same parameters.  I could not get the tool to run even when I isolated the toolbox code into a sub routine, and hard-coded the variables.

All the same references are loaded in the document too! 

Does anyone have any ideas?

The code is attached below in case it will help anyone help me!
Private Sub UIButtonControl1_Click()

    'Create the Geoprocessor object
    Dim GP As Object
    Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")
    

    'Get current folder (allows for relative positioning)
    Current_Folder = Left(Application.Templates.Item(Application.Templates.Count - 1), Len(Application.Templates.Item(Application.Templates.Count - 1)) - Len(ThisDocument.Title))

    'open tool box
    GP.Toolbox = Current_Folder & "Data\Python\zFEPS.tbx"
    
    output_folder = "C:\temp\test\"


    'Execute tools
    GP.scrFepsCopyFepsFromCat "YorkshireIndex", "True", "True", "True", "True", output_folder
    ^^^^^^^^^   is where the code fails on my XP machine.  It all works fine on my win2k machine
    
    'mergePDFs using PDFTK (http://www.accesspdf.com/pdftk/)
    (subsequent code will not have any effect - it's only shell and file system object stuff)
    
End Sub

0 Kudos
5 Replies
MarkWhitling
Deactivated User
sorry for shameless plug, but I am really struggling with this one.  Is there any other way of calling the GP object that I have missed that may perhaps work under XP?
0 Kudos
JoeVondracek
Regular Contributor
sorry for shameless plug, but I am really struggling with this one.  Is there any other way of calling the GP object that I have missed that may perhaps work under XP?


Are you certain that your CurrentFolder variable is what you think it is?  When I try your code in ArcMap 9.3.1 SP1 under Windows XP SP 3 using the project file D:\Untitled.mxd, what I get for ThisDocument.Title is "Normal.mxt". That of course means that CurrentFolder gets the wrong value, which means that the Geoprocessor object is going to have the wrong path to your toolbox.
0 Kudos
MarkWhitling
Deactivated User
Hi There,

I checked my code, and with the sample being pasted into ThisDocument as a simple sub routine, I get the full path..

See attached screen capture

So still no joy I'm afraid!

Mark
0 Kudos
JoeVondracek
Regular Contributor
Hmm.  Well, I don't know why your code isn't working, but the following works for me using ArcGIS 9.3.1 sp1 on Windows XP.  I have a toolbox named "Test Tools" that has a simple model in it, named "TestTool", which simply copies the input shapefile to the output shapefile.  I *think* that GPDispatch is the old way of doing things (pre 9.2) and ESRI recommends that you now use the Geoprocessor class instead.

Private Sub UIButtonControl1_Click()
   'Create the Geoprocessor object
    Dim GP As IGeoProcessor
    Set GP = New GeoProcessor

    'Get current folder (allows for relative positioning)
    Current_Folder = Left(Application.Templates.Item(Application.Templates.Count - 1), Len(Application.Templates.Item(Application.Templates.Count - 1)) - Len(ThisDocument.Title))
    
    GP.OverwriteOutput = True
    GP.AddToolbox (Current_Folder & "Test Tools.tbx")
    
    '//Declare and set a variant array to hold the parameters
    Dim parameters As IVariantArray
    Set parameters = New VarArray
    
    '//Populate the variant array with parameters
    parameters.Add "C:\temp\x.shp"
    parameters.Add "C:\temp\y.shp"
    
    '//There is a custom model named TestTool in the custom toolbox Test Tools.
    '//All it does is copy the first shapefile to a second shapefile, both of
    '//which are parameters to the model.
    GP.Execute "TestTool", parameters, Nothing
End Sub
0 Kudos
HalilSiddique
Frequent Contributor
I know this is an old thread, but I am having the exact same problem, I have tried the code above this post, but I still get the automation error message.
any ideas?
0 Kudos