I'm working on a python toolbox script, and I am able set all the script parameters in code. However, what I would like to be able to do is make new parameters or change some of the parameter properties at run-time. For example, if the user picks a value from the first parameter value list, the next parameter would get created based on the users selection. They pick SHAPEFILE from the list, the next parameter becomes datatype Shapefile and user can browse for a shapefile. They pick Use Mouse, the parameter becomes datatype Feature Set with schema set to allow user to draw box and select features.
The problem seems to be that none of the properties of the parameters can be modified outside the getParameterInfo function.
None of the parameter properties, other than param.enabled, seem to work. After trying to change the displayName of an existing parameter I get back error:
"updateParameters AttributeError: ParameterObject: Set attribute: displayName does not exist"
If I have to I will do it the ugly way and have two parameters when the tool opens and enable or disable them based on user input. However, if I could just create the parameter that I need, based on user input, that would be the best solution. This may just be beyond what PYT is capable of, but let me know if you have any ideas.
Thanks!
Tami O
The problem seems to be that none of the properties of the parameters can be modified outside the getParameterInfo function.
Code:
import arcpy
import os
class Toolbox(object):
def __init__(self):
self.label = "Buffer tools"
self.alias = "buffer"
# List of tool classes associated with this toolbox
self.tools = [BufferAddr]
class BufferAddr(object):
def __init__(self):
self.label = "Buffer Address Points"
self.description = "Test of a buffer tool "
def getParameterInfo(self):
#Define parameter definitions
selType = arcpy.Parameter(
displayName="Selection Type",
name="selType",
datatype="String",
parameterType="Required",
direction="Input")
selType.filter.list = ["SHAPEFILE","SELECT FEATURES WITH MOUSE"]
parameters = [selType]
return parameters
def isLicensed(self): #optional
return True
def updateParameters(self, parameters): #optional
##SHOULD BE ABLE TO CREATE NEW PARAMETER HERE OR ALTER EXISTING?
arcpy.AddMessage("the val is " + parameters[0].value)
if parameters[0].value=="SHAPEFILE":
##THIS BOMBS ----> parameters[0].displayName="SHAPEFILE"
arcpy.AddMessage("PICKED SHAPEFILE")
else:
arcpy.AddMessage("PICKED USER SEL")
return
def updateMessages(self, parameters): #optional
return
def execute(self, parameters, messages):
arcpy.env.overwriteOutput= True
selType=parameters[0].valueAsText
"updateParameters AttributeError: ParameterObject: Set attribute: displayName does not exist"
If I have to I will do it the ugly way and have two parameters when the tool opens and enable or disable them based on user input. However, if I could just create the parameter that I need, based on user input, that would be the best solution. This may just be beyond what PYT is capable of, but let me know if you have any ideas.
Thanks!
Tami O