Dear Community
When defining parameters in a .pyt (Python toolbox) I would like to make one of the parameters optional - I think.
It's a boolean parameter, allowing the user to specify weather the tool is allowed to overwrite certain values.
I have made it default to False, and that would be the correct setting in 9 of 10 cases, so I would prefer if the tool would be able to just go with this default value. Unfortunately, when run, the tool insist that I toggle the boolean, before it will remove the little green dot. If I run the tool with the default values untouched, it gives me an error-box saying: "ERROR 000735: Overwrite Existing OBJNAM and NOBJNM: Value is required"
I have tried to change the parameter from parameterType="Required", to parameterType="Optional", but it seems to have no effect on the tool behaviour.
I have decided to paste the entire code here, it's still 90% cut-and-paste from ArcGIS Help (10.2, 10.2.1, and 10.2.2) , ArcGIS Help (10.2, 10.2.1, and 10.2.2) , and others but I guess the error is in a combination of things, and not the isolated line.
I have marked the parameter (line 81), that I try to change to make a difference.
#-------------------------------------------------------------
# Name: GNDBtoolbox.pyt
# Purpose: A python-toolbox to work with the "Greenlandic Names Data Base" (GNDB) and NIS.
# Author: Martin Hvidberg
# e-mail: mahvi@gst.dk, Martin@Hvidberg.net
# Created: 2014-09-16
# Copyright: CopyLeft
# ArcGIS ver: 10.2.0
# Python ver: 2.7.3
#-------------------------------------------------------------
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the .pyt file)."""
self.label = "The_GNDB_Toolbox"
self.alias = "Toolbox to work with GNDB and NIS"
self.description = "This is the description of the toolbox..."
# List of tool classes associated with this toolbox
self.tools = [GNDBruninTOC]
class GNDBruninTOC(object):
"""
GNDB update NIS - assuming feature classes all ready opened in TOC
Created on 27 Sep 2011
@author: mahvi@gst.dk / Martin@Hvidberg.net
"""
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "GNDB_update_NIS_run_in_TOC"
self.description = "This tool will update the selected NIS FC, which must be in the TOC"
self.canRunInBackground = True # True = Obey "Background Processing setting" in the Geoprocessing Options dialog.
def getParameterInfo(self):
"""Define parameter definitions"""
# 0. The Feature layer to receive GNDB names
param0 = arcpy.Parameter(
displayName="Input Features",
name="in_features",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
# 1. The point feature class holding the GNDB
param1 = arcpy.Parameter(
displayName="GNDB points",
name="GNDB",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
param1.value = "NamesP"
# 2. The Mode
param2 = arcpy.Parameter(
displayName="The Mode",
name="Mode",
datatype="GPString",
parameterType="Required",
direction="Input")
param2.filter.type = "ValueList"
param2.filter.list = ["Berit", "Test"]
param2.value = param2.filter.list[0]
# 3. Overwrite
param3 = arcpy.Parameter(
displayName="Overwrite Existing OBJNAM and NOBJNM",
name="Overwrite",
datatype="GPBoolean",
parameterType="Optional", # <------ This seems to have no effect ?
direction="Input")
param3.value = "False"
params = [param0, param1, param2, param3]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
# put processing here ...
return