Creating a non-trival custom GP tool - inputs, outputs, and responding to environment settings
' Copyright 2008 ESRI
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' See use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.

Imports Microsoft.VisualBasic
Imports System
Imports ESRI.ArcGIS.Geoprocessing
Imports ESRI.ArcGIS.Geodatabase

Namespace GPPointFileInfo
  Public Class GPOutputGeometryDimensions
        Implements GPPointFileInfo.IGPOutputGeometryDimensions
    Private Shared _parameterIndex As Integer

    Private _geometryDimensions As String

    Public Sub New(ByVal parameterValueArray As IParameterValueArray)
      Dim gpValue As IGPValue = parameterValueArray.GetGPValue(_parameterIndex)

      Dim geometryDimensions As String = GetGeometryDimensions(gpValue)


      _geometryDimensions = geometryDimensions
    End Sub

    Public Shared Function GetGPParameterEdit() As IGPParameterEdit
      Dim gpParameterEdit As IGPParameterEdit = New GPParameterClass()

      Dim gpDataType As IGPDataType = New GPStringTypeClass()

      Dim gpCodedValueDomain As IGPCodedValueDomain = GetGPCodedValueDomain()

            Dim gpValue As IGPValue = gpCodedValueDomain.Value(0)

      Dim gpDomain As IGPDomain = TryCast(gpCodedValueDomain, IGPDomain)

      gpParameterEdit.Name = "in_output_geometry_dimensions"
      gpParameterEdit.DisplayName = "Output Geometry Dimensions"
      gpParameterEdit.DataType = gpDataType
      gpParameterEdit.Value = gpValue
      gpParameterEdit.Direction = esriGPParameterDirection.esriGPParameterDirectionInput
      gpParameterEdit.ParameterType = esriGPParameterType.esriGPParameterTypeRequired
      gpParameterEdit.Domain = gpDomain

      Return gpParameterEdit
    End Function

    Private Shared Function GetGPCodedValueDomain() As IGPCodedValueDomain
      Dim gpCodedValueDomain As IGPCodedValueDomain = New GPCodedValueDomainClass()

      gpCodedValueDomain.AddStringCode("2D", "2D")
      gpCodedValueDomain.AddStringCode("3D", "3D")

      Return gpCodedValueDomain
    End Function

    Public Shared Sub SetGPParameterIndex(ByVal index As Integer)
      _parameterIndex = index
    End Sub

        Public ReadOnly Property GeometryDimensions() As String Implements IGPOutputGeometryDimensions.GeometryDimensions
                Return _geometryDimensions
            End Get
        End Property

    Private Function GetGeometryDimensions(ByVal gpValue As IGPValue) As String
      Dim geometryDimensions As String

      Dim gpString As IGPString = TryCast(gpValue, IGPString)

      geometryDimensions = gpString.Value

      Return geometryDimensions
    End Function

    Private Sub ValidateGeometryDimensions(ByVal geometryDimensions As String)
      Dim gpCodedValueDomain As IGPCodedValueDomain = GetGPCodedValueDomain()

      Dim gpString As IGPString = New GPStringClass()

      gpString.Value = geometryDimensions

      Dim gpValue As IGPValue = TryCast(gpString, IGPValue)

      Dim name As String = gpCodedValueDomain.FindName(gpValue)

      If name Is Nothing Then
        Throw New GPException(GPExceptionSeverity.Error, "Invalid Output Geometry Dimensions. Geometry Dimensions Do Not Fall Within Domain Of Valid Values." & ObjectToString.GetNewline() & "geometryDimensions: " & ObjectToString.GetToString(geometryDimensions))
      End If
    End Sub
  End Class
End Namespace