Tool has no parameter - Can't create python toolbox parameters ?

1795
3
Jump to solution
09-26-2013 10:16 PM
OlivierOlivier
New Contributor III
Hi,

Instead of using a classic toolbox, I wanted to try to create a .pyt python toolbox. So I Created a .pyt file with Add/New python toolbox. I kept the template and just add added what I thought what was the parameter definition

def getParameterInfo(self):         """Define parameter definitions"""         params = arcpy.Parameter(             displayName="Input Features",             name="in_features",             datatype="DEDatasetType",             parameterType="Required",             direction="Input")         return params


But when I run the tool,
- I still get "this tool has no parameter"
- if I just add a print "test" in the execute method, it doesn't appear.

In a .pyt, there is no "parameters" tab, so I don"t understand how to add the widget gui. I went thru documentation and didn't understand what I missed.

Thanks for any help.

Olivier

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 = "Toolbox"         self.alias = ""          # List of tool classes associated with this toolbox         self.tools = [Tool]   class Tool(object):     def __init__(self):         """Define the tool (tool name is the name of the class)."""         self.label = "Tool"         self.description = ""         self.canRunInBackground = False      def getParameterInfo(self):         """Define parameter definitions"""         params = arcpy.Parameter(             displayName="Input Features",             name="in_features",             datatype="DEDatasetType",             parameterType="Required",             direction="Input")         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."""         print "test"         return
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohnDye
Occasional Contributor III
'params' should be a list object containing your individual parameters.

So change the parameter from 'params' to param0, create a list object named params, populating 'param0' in the list and return the list.

def getParameterInfo(self):         """Define parameter definitions"""         param0 = arcpy.Parameter(             displayName="Input Features",             name="in_features",             datatype="DEDatasetType",             parameterType="Required",             direction="Input") params = [param0]  return params

I would have thought you could do it the way you did, but apparently if your not getting anything returned, you can't. Easy fix though, just a bit more code.

View solution in original post

0 Kudos
3 Replies
Luke_Pinner
MVP Regular Contributor
Try returning a list instead of a parameter -  i.e return [param]
0 Kudos
JohnDye
Occasional Contributor III
'params' should be a list object containing your individual parameters.

So change the parameter from 'params' to param0, create a list object named params, populating 'param0' in the list and return the list.

def getParameterInfo(self):         """Define parameter definitions"""         param0 = arcpy.Parameter(             displayName="Input Features",             name="in_features",             datatype="DEDatasetType",             parameterType="Required",             direction="Input") params = [param0]  return params

I would have thought you could do it the way you did, but apparently if your not getting anything returned, you can't. Easy fix though, just a bit more code.
0 Kudos
OlivierOlivier
New Contributor III
Thanks, Luke and John, it works ! I wished I could add one point to both of you, but as I got only one, I gave it to the one who earned less.
0 Kudos