MG1986

Python Script Tool Validation errors

Discussion created by MG1986 on Jan 4, 2014
Latest reply on Jan 6, 2014 by MG1986
I am currently creating a python script tool at work that works fine, and could be even more polished if I can get certain functionality working using the tool validation.  I am trying to get the tool to recognize what the the geometry type of the first input is, and based on that, set a parameter further down as a required parameter if its a "Polygon", or not required if it is a "Point".  Here is my code so far:

import arcpy

class ToolValidator(object):

  def __init__(self):
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
 
        [INDENT]return[/INDENT]

  def updateParameters(self):
    if self.params[0].value:
desc = arcpy.Describe(self.params[0].value)
feature_type = desc.shapeType
if feature_type == "Polygon":
  self.params[7].enabled = True
  self.params[7].parameterType = "Required"
                self.params[8].enabled = False
  self.params[8].parameterType = "Optional"
elif feature_type == "Point" or "Multipoint":
  self.params[7].enabled = False
  self.params[7].parameterType = "Optional"
  self.params[8].enabled = True
  self.params[8].parameterType = "Required"
 
       [INDENT]return[/INDENT]

  def updateMessages(self):

        [INDENT]return[/INDENT]


I have gotten it to recognize the geometry type of the first input once someone sets it. When its "Polygon", it will disable parameter[8], and when its "Point", it will disable parameter[7].  My problem is with with trying to toggle the parameterType property of a Parameter object, as suggested http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000063000000 here.  It says that the parameterType property is both read and write using tool validation.  For whatever reason, I cannot get it to work.  Ultimately, if the input geometry type is "Polygon", I would like parameter[7] set to parameterType "Required" and parameter[8] set to disabled.  If the input type is "Point", I would like parameter[8] set to parameterType "Required" and parameter[7] set to disabled. Any help is appreciated.

Outcomes