Show Navigation | Hide Navigation
You are here:
Geoprocessing > Automating your work with scripts > Accessing tools within a geoprocessing script

Using ArcObjects as tool input

Release 9.3
Last modified June 3, 2010
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Accessing tools within a geoprocessing script"


Note: This topic was updated for 9.3.1.

ArcObjects is the development platform for the ArcGIS family of applications, which includes ArcMap, ArcCatalog, and ArcScene. The ArcObjects software components expose the full range of functionality available in ArcInfo, ArcEditor, and ArcView to software developers. These objects can be used to manage geographic data, such as the contents of a geodatabase, shapefiles, and coverages, to name a few. If you are accustomed to working with ArcObjects, you can continue with that object model when working with the geoprocessor. An ArcObjects component can be used instead of an ArcCatalog path when defining an input parameter to a tool if the parameter accepts layers as valid input. For example, an IFeatureClass object can be used to define the input to the Clip tool in the Analysis toolbox, while an IRasterDataset object may be used as input to the Slope tool. The CreateFeatureClass tool will not accept an ArcObjects component as the input location, which could be a folder, geodatabase, or geodatabase feature dataset, since none of these data types can be represented as a layer. An ArcCatalog path must be used to define newly created tool output. Append updates existing data, so its output may be defined using an ArcObject, such as an IFeatureLayer.

Below is an example of using an ArcObjects component as input to a tool in Visual Basic for Applications (VBA):

Public Sub ClipFC()

  Dim filePath As String
  filePath = "D:\st_johns"
  Dim inputName As String
  Dim clipName As String
  inputName = "roads.shp"
  clipName = "urban_area.shp"

  Dim pWorkspace As IWorkspace
  Dim pFact As IWorkspaceFactory
  Set pFact = New ShapefileWorkspaceFactory
  Set pWorkspace = pFact.OpenFromFile(filePath, 0)
  Dim pFWorkspace As IFeatureWorkspace
  Set pFWorkspace = pWorkspace

  Dim pInfc As IFeatureClass
  Dim pClipfc As IFeatureClass
  Set pInfc = pFWorkspace.OpenFeatureClass(inputName)
  Set pClipfc = pFWorkspace.OpenFeatureClass(clipName)

  Dim pGP As Object
  Set pGP = CreateObject("esriGeoprocessing.GPDispatch.1")

 On Error GoTo EH
  pGP.Workspace = filePath
  pGP.Clip_analysis pInfc, pClipfc, "clipfc.shp"

  Exit Sub 
EH:
  MsgBox pGP.GetMessages(), vbOKOnly, "Clip"
End Sub


The geoprocessor object can be used in Visual Basic or VBA to execute any geoprocessing tool. When used in VBA, any resulting tool messages are captured in the Command Line window. The geoprocessing history model is also updated with a record of any tool that is executed.
Learn more about working with ArcObjects
Learn more about the Command Line window

Learn more about using environment settings

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.