Select to view content in your preferred language

PLS Help: Using VB6 to access Geoprocessing Object

940
3
06-29-2011 06:02 AM
CraigGraham
Occasional Contributor
Good Morning,
having trouble moving a 9.2 tool to 9.3.1.  The code below works great on 9.2:

Public Sub subMakeLines(sAccum As String, sImpedAtt As String, sDefBreakVal As String, sOutPath As String, sNetworkPath As String, sFacilitySHPName As String, sOutName As String, sOutPolyName As String)
 
    Dim pGp As Object, pFLayer As IFeatureLayer2, pFClass As IFeatureClass
    Dim pDS As IDataset
    Dim sBarrierPath As String, sTempFolder As String, FSO As New FileSystemObject, sServiceAreaName As String

183:     frmExportFeaturesToSHP.lbStatus = "Processing: " & Globals.g_iFeatNum & " of " & Globals.g_iFeatCount & " Facilities!"
184:     frmExportFeaturesToSHP.Refresh
'185:     sServiceAreaName = "LineServiceArea_" & Globals.g_iFeatNum
186:     sServiceAreaName = "LineServiceArea"
187:     Set pGp = CreateObject("esriGeoprocessing.GpDispatch.1")
188:     pGp.OverwriteOutput = 1
189:     pGp.Toolbox = "C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Network Analyst Tools.tbx"
190:     pGp.MakeServiceAreaLayer_na sNetworkPath, sServiceAreaName, sImpedAtt, "TRAVEL_FROM", sDefBreakVal, g_sPolyType, g_sMultiFacOptions, g_sOverlapType, g_sLineType, g_sOverlapTypeLines, g_sSplitLinesAtSrvAreaBreak, g_sExcludedSources, sAccum, "ALLOW_UTURNS", "", g_sTrimPoly, g_sTrimThres, "LINES_SOURCE_FIELDS"


But at 9.3.1 it doesn't work.  We think the issue is the way we are initializing the pGp

I think that I need to do something along the lines of replacing line 187 with:

187:     import arcgisscripting
188:     pGp = arcgisscripting.create(9.2)


Is this roughly how it is done?  Would it be 9.2 b/c that's the version I have on the development machine? or would I use 9.3 as that is the version on the target/testing machine.

Many thanks in advance for any and all suggestions.

Take care,
C
0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor
Craig,

The lines of code 187 & 188 you are suggesting is python code which is not VB. I have 9.3 and the CreateObject function on line 187 works fine for me so this makes me wonder if ESRI have done something behind the scenes in 9.3.1. Can someone clarify this?

ESRI want us to use the new way of creating a GeoProcessor object, the IGeoProcessor. You can still call the standard tools using this new interface you just do it differently. I find it actually easier to use, as the intellisense works.

Do a search on the old forum for IGeoProcessor and you'll see lots of examples of how to construct it and invoke tools with it.

Duncan
0 Kudos
CraigGraham
Occasional Contributor
Duncan, thanks so much for your reply. 


The lines of code 187 & 188 you are suggesting is python code which is not VB. I have 9.3 and the CreateObject function on line 187 works fine for me so this makes me wonder if ESRI have done something behind the scenes in 9.3.1. Can someone clarify this?


In the meantime we've been testing stuff out and we cant replicate the errors that the user is reporting.  And the syntax I have in line 187 is what we've used in the past.  But it is failing on that line.


ESRI want us to use the new way of creating a GeoProcessor object, the IGeoProcessor. You can still call the standard tools using this new interface you just do it differently. I find it actually easier to use, as the intellisense works.


That is great news going forward.  That will be a big help. 

Thanks again,
Craig
0 Kudos
DuncanHornby
MVP Notable Contributor
Here is a sample of how to set up the IGeoProcessor, in this example they are calling a custom tool but it could equally be a standard esri tool. You just need to be careful in the order you add the tools parameters to the array object, this must be the same as how you would fill in the tool.

Duncan
0 Kudos