Extract by mask run time error in VBA

388
1
12-15-2011 10:37 AM
New Contributor
I have the following script language code shown below within a main code just to run the tool of spatial analyst "Extract by mask". Unfortunately, when I run it I get a Run Time Error. I checked file names etc. but I cannot find the problem. Could anybody help me please? Thanks.

Dim GP As Object
Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")

GP.AddToolbox "C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst  Tools.tbx"

InRaster = "C:\LACONISS\LandSpaCES\valuationmapr"
InMask = "C:\LACONISS\LandSpaCES\Parcel165"
OutRaster = "C:\LACONISS\LandSpaCES\ParcelR165"

GP.CheckOutExtension ("Spatial")

GP.ExtractByMask_sa InRaster, InMask, OutRaster
Reply
0 Kudos
1 Reply
by
Occasional Contributor
Are you working with ArcGIS Desktop 9.3.1/10? Your codes looks for version 9.1 or earlier.

Here are the updated codes:


'Check out Spatal Analyst extension
Dim ao As IAoInitialize
Set ao = New AoInitialize
ao.CheckOutExtension (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst)

'Add Spatial Analyst Toolbox
Dim gp As IGeoProcessor
Set gp = New GeoProcessor
gp.AddToolbox "C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx"

'Define input parameters for the Extract by Mask tool
Dim parameters As IVariantArray
Set parameters = New VarArray
parameters.Add ("C:\LACONISS\LandSpaCES\valuationmapr")
parameters.Add ("C:\LACONISS\LandSpaCES\Parcel165")
parameters.Add ("C:\LACONISS\LandSpaCES\ParcelR165")

'Run the Extract by Mask GP tool
gp.Execute "ExtractByMask", parameters, Nothing
Reply
0 Kudos