Open Table of Contents

Scripting - Getting Started

I. In order to use ET GeoWizards scripting you need to have:

  1. Installed ArcGIS 8.1 and above (ArcView, ArcEditor or ArcInfo license)
  2. Installed ArcGIS Desktop  Developers Kit
  3. Installed ET GeoWizards 9.0 or above. Note that the Scripting is only available for the registered users of the software. The users with a not registered version can use the functionality available on small (up to 100 features) datasets only

II. Opening the VBA development environment in ArcGIS

In ArcMap go to Tools ==> Macros ==> Visual Basic Editor

It is highly recommended to read the "Visual Basic for Applications Development Environment" of the ArcObjects developers help for detailed instructions

III. Loading ET GeoWizards library

When in the Visual Basic Editor go to Tools ==> References, find etgw90_8x or etgw90_9x  (depending on the ET GeoWizards version you use ) and check the box in front of it.

IV. Creating a new module

In the VBA Editor go to the Project window ==> Right click on Module ==> Insert ==> Module. This will create a new VBA module for you. 

V. Let's assume that we have a polyline layer and want to build a polygon dataset from it.  

Option Explicit ' This line will help debugging your script
Public Sub BuildPolygons() ' The name is up to you ( it should describe the function to be performed)
 ' we need the code to perform the Build Polygons function here
End Sub  'indicates the end of the procedure  

VI. Some basic stuff that might be needed before proceeding. The code below is standard ArcObjects VBA and can be applied with all functions available in ET GeoWizards. 

Option Explicit ' This line will help debugging your script
Public Sub BuildPolygons() ' The name is up to you ( it should describe the function to be performed)
   'We need to declare some variables needed
    Dim pMxDoc As IMxDocument ' The document we are working in
    Dim pMap As IMap ' The Map
    Dim pFeatureLayer As IFeatureLayer 'We'll need to take a source polyline layer
    Dim pInFeatureClass As IFeatureClass 'Then the source Feature Class
    Dim pOutFeatureClass As IFeatureClass 'As a result we have to create a new feature class
    'Now we need to set values to the variables needed
    Set pMxDoc = ThisDocument 'Current document
    Set pMap = pMxDoc.FocusMap' Get the Map
    Set pFeatureLayer = pMxDoc.SelectedLayer ' Get the selected layer from the map
    Set pInFeatureClass = pFeatureLayer.FeatureClass ' Get the feature class from the selected layer
   '===========================================================

    ' Here we need to perform some action on the input layer and get the resulting feature class
   '======================================================================== 
   
Set pFeatureLayer = New FeatureLayer ' Create a new feature layer
    Set pFeatureLayer.FeatureClass = pOutFeatureClass ' set the source of this layer
    pFeatureLayer.Name = pOutFeatureClass.AliasName ' set the name of the layer
    pMap.AddLayer pFeatureLayer ' add the layer to the map
End Sub  'indicates the end of the procedure  

VII. Here we just add the appropriate ET GeoWizards function to the basic code above

Option Explicit
Public Sub BuildPolygons()
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pFeatureLayer As IFeatureLayer
    Dim pInFeatureClass As IFeatureClass
    Dim pOutFeatureClass As IFeatureClass
    
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Set pFeatureLayer = pMxDoc.SelectedLayer
    Set pInFeatureClass = pFeatureLayer.FeatureClass
   '=======================================================================
   ' The code below is specific for the BuildPolygons function.
   'It can be replaced with the examples available for each function in this User Guide
    Dim ET As New ETGW_Core 'Declare the ET GeoWizards library
    Dim sOutFileName as String 'Declare the name of the resulting feature class
    Dim bClean as Boolean 'Declare a variable that will define whether a clean will be performed
    Dim dFuzzyTol as Double
'Declare a fuzzy tolerance variable
    bClean = True
' Set that the polylines will be cleaned before Build
    dFuzzyTol = 0.0001
' Set the tolerance to be used for cleaning
    sOutFileName = "c:\00\polygons.shp"
' Set the output feature class
    Set pOutFeatureClass = ET.BuildPolygons(pInFeatureClass, sOutFileName , bClean , dFuzzyTol
)
   
'end of the function specific code
    '========================================================================
    Set pFeatureLayer = New FeatureLayer
    Set pFeatureLayer.FeatureClass = pOutFeatureClass
    pFeatureLayer.Name = pOutFeatureClass.AliasName
    pMap.AddLayer pFeatureLayer
End Sub

Note that all the function specific code above can be replaced by a two line code

Dim ET As New ETGW_Core
Set pOutFeatureClass = ET.BuildPolygons(pInFeatureClass, "c:\00\polygons.shp" , True , 0.0001)