Geoprocessing Error VB.NET

2421
4
01-11-2011 03:58 AM
BrentErmis
New Contributor
I am fairly new to the VB.NET world.  I am getting an error when I try to call a model via VB.NET code.  Below is the code that I am using:

       
Try
            Dim GP As Geoprocessor = New Geoprocessor()

            GP.AddToolbox("C:\Documents and Settings\bxe6736\Application Data\ESRI\ArcToolbox\My Toolboxes\Centerline(Local).tbx")
            GP.Execute("Centerline", Nothing, Nothing)

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly, "")
        End Try


It falls into the error on the gp.execute command.  I have attached the error that I am getting.  I have checked the folder that I am writing the data to and it doesn't seem to be a permissions problem.
0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
bxe6736,

Is this your real name?

The only thing I spotted with your code snippet is the line:
Dim GP As Geoprocessor = New Geoprocessor()


I think should be:

Dim GP As IGeoprocessor = New Geoprocessor()


If this does not fix your problem it would help us if you uploaded the toolbox, does the model have parameters for example as you are supplying none?

Duncan
0 Kudos
BrentErmis
New Contributor
bxe6736,

Is this your real name?

The only thing I spotted with your code snippet is the line:
Dim GP As Geoprocessor = New Geoprocessor()


I think should be:

Dim GP As IGeoprocessor = New Geoprocessor()


If this does not fix your problem it would help us if you uploaded the toolbox, does the model have parameters for example as you are supplying none?

Duncan


Ok Duncan fixed half of the problem.  Thanks for the heads up on the IGeoProcessor tip.  Now I am getting another error on the gp.execute line:

Error HRESULT E_FAIL has been returned from a call to a COM component.

Here is the new code that I am using:
Dim GP As IGeoProcessor            
GP = New GeoProcessor

            GP.AddToolbox("C:\Documents and Settings\bxe6736\Application Data\ESRI\ArcToolbox\My Toolboxes\Toolbox.tbx")

            ''''Run Model 1

            '' Model 1 Inputs
            parameters.Add("\\Corcosaps02a\cig-eng_nt\User\PUBLIC\Public Awareness\IRTH\ISAT.mdb\ControlPointsSNG")
            parameters.Add("\\Corcosaps02a\cig-eng_nt\User\PUBLIC\Public Awareness\IRTH\ISAT.mdb\ControlPointsTGP")
            parameters.Add("\\Corcosaps02a\cig-eng_nt\User\PUBLIC\Public Awareness\IRTH\ISAT.mdb\tblStaticAddsTGP")
            parameters.Add("\\Corcosaps02a\cig-eng_nt\User\PUBLIC\Public Awareness\IRTH\ISAT.mdb\tblStaticAddsSNG")
            parameters.Add("\\Corcosaps02a\cig-eng_nt\User\PUBLIC\Public Awareness\IRTH\ISAT.mdb\ControlPointsAbandoned")
            '' Model 1 Outputs
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\ControlPointsAbandoned_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\tblStaticAddsTGP_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\tblStaticAddsSNG_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\ControlPointsSNG_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\ControlPointsTGP_Copy.shp")

            GP.Execute("Model3", parameters, Nothing)

            parameters = Nothing

            MsgBox("Model 1 Complete", MsgBoxStyle.OkOnly, "")

            ''''Run Model 2
            '' Model 2 Inputs
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\ControlPointsAbandoned_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\tblStaticAddsTGP_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\tblStaticAddsSNG_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\ControlPointsSNG_Copy.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\ControlPointsTGP_Copy.shp")
            '' Model 2 Outputs
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\Aban_OneCall_CL.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\TGP_ADD.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\TGP_CL.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\SNG_CL.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\SNG_ADD.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\TGP_OneCall_CL.shp")
            parameters.Add("C:\Documents and Settings\bxe6736\Desktop\New Folder\Centerline(Local)\SNG_OneCall_CL.shp")

            GP.Execute("Centerline", parameters, Nothing)

            parameters = Nothing

            MsgBox("Model 2 Complete", MsgBoxStyle.OkOnly, "")


Any Suggestions??

Brent
0 Kudos
DuncanHornby
MVP Notable Contributor
Brent,

OK, first thing first, if you run your model from ArcMap and supply those parameters exactly how you've written them does the model execute without a problem?  I ask this as you have brackets a spaces in your path names.  If you are not getting an error running it as a model then it suggests something is going wrong with the parameters. Also the execute method returns an object of type IGeoProcessorResult. Maybe you should get a hold of that and see what kind of error message it's returning?

Have you set you parameters object to IVariantArray?

Duncan
0 Kudos
BrentErmis
New Contributor
Thanks for the help Duncan.  The problem was some of the parameters were not set.

Now for the next step.  I am trying to get a progress bar to run while the geoprocessing task is running.  I have not been able to get them to run at the same time.  I have code if that will help.
0 Kudos