I want to execute one of my tools (which I created with Model Builder). I can execute a built-in tool by this code, but when I change the tool name with Model Tool Names it doesn't work.

I gathered information about referencing a new *.tbx file into a VB.Net project but it doesn't work properly. (When I use 'ArcGIS Toolbar Reference', nothing happens.)
Please help me.

This is my code for built-in tools:

Public Function CreateTempFileGDB() As Boolean

    Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = Nothing
    GP = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()

    GP.OverwriteOutput = True

    Dim parameters As IVariantArray = New VarArray

        GP.Execute("CreateFileGDB_management", parameters, Nothing)
    Catch ex As Exception
        Return False
    End Try

    Return True

End Function

1 Answer 1


As @ujjwalesri pointed out, you need a reference to the toolbox. Here is an example that works for me:

Dim gp_msg As String = ""
Dim pGp As ESRI.ArcGIS.Geoprocessing.IGeoProcessor
Dim pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult
Dim pParamArray As ESRI.ArcGIS.esriSystem.IVariantArray
Dim minZ As Double
Dim MaxZ As Double
Dim TinPath As String
Dim VolumeInterval As Double
Dim loopValue As Integer
Dim LoopElevationLevel As Double

TinPath = InputBox("Enter Path to the TIN:")

MaxZ = InputBox("Enter maximum elevation plane height starting value: ", "Maximum Plane Height - Custom Value", Math.Round(MaxZ))

minZ = InputBox("Enter minimum elevation: ", "Adjust Minimum Elevation", Math.Round(minZ))

VolumeInterval = InputBox("Enter INTERVAL:", "Volume Elevation Calculation Interval", 1)

loopValue = (MaxZ - minZ) / VolumeInterval

pGp = New ESRI.ArcGIS.Geoprocessing.GeoProcessor

pGp.OverwriteOutput = True

'Add the custom toolbox containing the model tool
pGp.AddToolbox("C:\Users\User\AppData\Roaming\ESRI\Desktop10.0\ArcToolbox\My Toolboxes\Toolbox.tbx")

LoopElevationLevel = MaxZ
Do Until LoopElevationLevel < minZ

    'Create the Parameter array (every iteration within loop - elevation changes)
    pParamArray = New ESRI.ArcGIS.esriSystem.VarArray

    'Populate array of parameters
    pParamArray.Add(TinPath) 'TIN
    pParamArray.Add(LoopElevationLevel) 'elevation

    'Execute the Model tool
    pResult = pGp.Execute("VolumeBellow", pParamArray, Nothing)

    gp_msg = gp_msg & ReturnMessages(pResult) & Chr(13)

    LoopElevationLevel = LoopElevationLevel - VolumeInterval             

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.