0

I made a function which should execute a custom ArcGIS model. I use VB 2010 with ArcGIS 10.2. The button which should execute this function is placed on a dockable window.

    Dim model As Geoprocessor = New Geoprocessor()
    model.AddToolbox("D:\Chris\Van Hall Larenstein\Ruimtelijke Informatie Technologie\RPS\RPS.tbx")

    Dim parameters As ESRI.ArcGIS.esriSystem.IVariantArray = New ESRI.ArcGIS.esriSystem.VarArrayClass()
    model.Execute("RPS_TEST", parameters, Nothing)

There are no errors reported in VB 2010, but it doesn't work in ArcGIS. What am I doing wrong?

EDIT:

    Dim pToolHelper As IGPToolCommandHelper2 = New GPToolCommandHelper

    'Set the tool you want to invoke.
    Dim toolboxPath = "C:\Program Files\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\Analysis Tools.tbx"
    pToolHelper.SetToolByName(toolboxPath, "Buffer")

    'Create the messages object to pass to the InvokeModal method.
    Dim msgs As IGPMessages
    msgs = New GPMessages

    'Invoke the tool.
    pToolHelper.InvokeModal(0, Nothing, True, msgs)
    My.ArcMap.Application.CurrentTool = Nothing

Chris Driessen

Chris Driessen
  • 15
  • 1
  • 1
  • 5

1 Answers1

0

If you want user define parameters than this is not the way to do it. Your code immediately executes the model (without the parameters).

See this link on how to open geoprocessing tool dialog.

Zeljko Vujaklija
  • 500
  • 4
  • 12
  • This does not work for the Buffer tool, and does not work for the custom model. VB does not give me errors, but in ArcGIS: Error HRESULT E_FAIL has been returned from a call to a COM component. – Chris Driessen Jan 21 '15 at 08:48
  • It works for all tools. You must be doing something wrong. Could you post your code? – Zeljko Vujaklija Jan 21 '15 at 10:27
  • See orignal question; I copied the code from Arcobjects. But maby this code isn't compatible in VB 10 and ArcGIS 10.2? – Chris Driessen Jan 21 '15 at 12:01
  • OK, this is strange. I rewrote your code in C# (I don't have VB.NET installed) and it works. The only differences are in the path of the toolbox and ArcGIS version. I have 32 bit ArcGIS 10.1 version. Yours is 64 bit judging by the path. It also works in 10.0. – Zeljko Vujaklija Jan 21 '15 at 13:13
  • Did you execute your code from with a button on a dockable window, or from a UI button in the ArcGIS toolbar? – Chris Driessen Jan 21 '15 at 14:03
  • I don't think this is a solution. Do you agree? http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001sw000000 – Chris Driessen Jan 21 '15 at 14:19
  • I executed code from a button, but it doesn't matter from where it is executed. Regarding link you posted - it uses same code you already tried with your custom model. What ArcGIS licence do you have? I think Buffer tool requires Advanced license. Maybe your custom model also uses tool(s) that require license level you don't have? – Zeljko Vujaklija Jan 21 '15 at 20:10
  • When I execute the model from the toolbox it works fine. So I don't think that is the problem. – Chris Driessen Jan 22 '15 at 08:27