I am a novice in programming and am trying to clean up a previous employee's script. Since the migration to ArcGIS v10 our scripts have needed a bit of scrubbing due to the LITTLE nuances of v10 modifications.
Everything works up until "LoadDentonParcels". It is here that the model will not run. I have attempted to split up the models and take it to the point of the Join Field and it will run appropriately with the right outputs. When it gets to the Join Field, it initially bombed because of the naming limitations, so I then added a "Copy Rows" to a shorter named table. This runs in Model Builder but will not run when using Visual Studio 2010. I continue to receive the following error (very generic) - "A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in ESRI.ArcGIS.Geoprocessor.dll" I can't help but think that I am missing some library somewhere or there is a bug with some of the tools. As I previously mentioned, three of the previous models worked.
The following references have been added:
ESRI.ArcGIS.ArcCatalog
ESRI.ArcGIS.Geoprocessing
ESRI.ArcGIS.Geoprocessor
ESRI.ArcGIS.System
ESRI.ArcGIS.Version
GPMetadataFunctions (which was added after debugging a previous error)
MetadataTranslator
System
System.Data
Here is the following code:
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geoprocessing
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Text
Imports System
Module modParcelsImport
Private m_AOLicenseInitializer As LicenseInitializer = New ParcelsImport.LicenseInitializer()
#Region "Member Variables"
Private m_swLog As IO.StreamWriter
#End Region
<STAThread()> _
Function Main(ByVal cmdLineArg() As String) As Integer
'ESRI License Initializer generated code.
If (Not m_AOLicenseInitializer.InitializeApplication(New esriLicenseProductCode() _
{esriLicenseProductCode.esriLicenseProductCodeArcInfo}, _
New esriLicenseExtensionCode() {})) Then
LogMessage(m_AOLicenseInitializer.LicenseMessage())
Return 1
End If
Dim server As String = Nothing
Dim logPath As String = Nothing
Dim arctoolboxPath As String = Nothing
'Dim pGeoProcessor As IGeoProcessor = New GeoProcessor
Dim pGeoProcessor As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor
Console.WriteLine("Validating parameters...")
' Verify it meets number of required parameters
'If Not (cmdLineArg.Length = PARAMETER_NUMBER) Then
' Call outputSyntax()
' Return 1
'End If
'' Validates server name
'If GetArgValue(cmdLineArg, "-s", server) Then
' Console.WriteLine("Error: Invalid Input. Verify syntax.")
' Console.WriteLine(System.Environment.NewLine)
' Call outputSyntax()
'Else
' If Not (server.ToUpper.StartsWith("GS")) Then
' Console.WriteLine("Error: Invalid Server Name.")
' Return 1
' End If
'End If
'' Create file to log results
'If GetArgValue(cmdLineArg, "-o", logPath) Then
' Console.WriteLine("Error: Invalid Input. Verify syntax.")
' Console.WriteLine(System.Environment.NewLine)
' Call outputSyntax()
'Else
' Try
' m_swLog = New IO.StreamWriter(IO.File.Open(logPath, IO.FileMode.Create))
' Catch ex As Exception
' Console.WriteLine(ex.Message)
' Return 1
' End Try
'End If
'' Create geoprocessor (open toolbox)
'If GetArgValue(cmdLineArg, "-tbx", arctoolboxPath) Then
' Console.WriteLine("Error: Invalid Input. Verify syntax.")
' Console.WriteLine(System.Environment.NewLine)
' Call outputSyntax()
'Else
' Try
' ' Add toolbox
' pGeoProcessor.AddToolbox(arctoolboxPath)
' pGeoProcessor.OverwriteOutput = True
' Catch ex As Exception
' Console.WriteLine("Error: The ArcToolbox was not found.")
' Return 1
' End Try
'End If
server = "GS005"
'm_swLog = New IO.StreamWriter(IO.File.Open("C:\logs\ParcelsImportLog_New.txt", IO.FileMode.Create))
pGeoProcessor.AddToolbox("C:\ArcGIS\Custom\ArcToolboxes\ImportParcels.tbx")
pGeoProcessor.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
pGeoProcessor.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Conversion Tools.tbx")
pGeoProcessor.OverwriteOutput = True
' log starting time
LogMessage("Starting application at " & Now)
' Instantiate Object to hold model's parameters
Dim pParamArray As IVariantArray = New VarArrayClass
' Execute model
'If RunModel("CreateStagingFeatureClass", pGeoProcessor, pParamArray) Then
' Return 1
'End If
' '' Execute model
'If RunModel("LoadTarrantParcels", pGeoProcessor, pParamArray) Then
' Return 1
'End If
' Execute model
If RunModel("LoadDentonParcels", pGeoProcessor, pParamArray) Then
Return 1
End If
' Execute model
If RunModel("DentonJoin", pGeoProcessor, pParamArray) Then
Return 1
End If
' Execute model
If RunModel("CalculateDenton", pGeoProcessor, pParamArray) Then
Return 1
End If
' Execute model
If RunModel("DeleteTempFCs", pGeoProcessor, pParamArray) Then
Return 1
End If
' Drop connections to parcels and parcels_View
Call DropConnections(server)
' Execute model
If RunModel("DeleteCreateParcelsFC", pGeoProcessor, pParamArray) Then
Return 1
End If
pGeoProcessor.OverwriteOutput = True
Try
' Execute model
If RunModel("GrantPermissions", pGeoProcessor, pParamArray) Then
Return 1
End If
' Checkin licenses
m_AOLicenseInitializer.ShutdownApplication()
' Log finishing time
LogMessage("Finished Application at " & Now)
Return 0
End Function
Private Function GetArgValue(ByVal argArray() As String, ByVal opt As Char(), ByRef parameter As String)
' Get parameter values
For index As Integer = 0 To (argArray.Length - 1)
' Look for the given option
If argArray(index).Contains(opt) Then
Try
' Check to make sure there is an additional element in the array
If argArray.Length > (index + 1) Then
parameter = argArray(index + 1).ToString
Else
' No additional element found after the option
Return 1
End If
Exit For
Catch ex As Exception
Console.WriteLine(ex.Message)
Return 1
End Try
End If
Next
Return 0
End Function
Private Function RunModel(ByVal modelName As String, ByRef pGP As ESRI.ArcGIS.Geoprocessor.Geoprocessor, ByVal pParamArray As IVariantArray)
LogMessage("====================Executing " & modelName & " model====================")
' Create object to store result messages
Dim pResult As IGeoProcessorResult
Try
' Execute model and get message
pResult = pGP.Execute(modelName, pParamArray, Nothing)
' Get message
Call ReturnMessages(pResult)
' Make sure job succeded
If pResult.Status = esriJobStatus.esriJobSucceeded Then
Return 0
Else
LogMessage(modelName & " model failed.")
Return 1
End If
Catch ex As Exception
LogMessage(ex.Message)
Return 1
End Try
End Function
Public Sub ReturnMessages(ByVal messages As IGeoProcessorResult)
Dim index As Long
Dim message As String
' loop thru messges and save them to the log
For index = 0 To messages.MessageCount - 1
message = messages.GetMessage(index)
LogMessage(message)
Next
End Sub
End Module
Running on ArcGIS 10 SP3, Visual Studio 2010, Windows XP Prof, SQL 2008 R2
Any help would be SO appreciated! Thank you!