0

I have been posting similar questions recently, but I found a template code for a Python toolbox and I would like more help.

I am trying to create a tool in ArcGIS Pro that takes parameters from users (initially, the geodatabase filename) and shows the report on the screen.

I added to the template the function "getParameter." I thought this function will open up a dialog box for a user to choose a parameter, but it does not for some reason.

The following code has no syntax error. When I add a new Python toolbox and ran this code, it does run, but it says "no parameters," as the screenshot says. What change do I need to make?enter image description here

import arcpy
import os
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 = [Report]
class Report(object):
 def __init__(self):
 """Define the tool (tool name is the name of the class)."""
 self.label = "Tool"
 self.description = ""
 self.canRunInBackground = False
 def getParameter(self): 
 arcpy.env.workspace = arcpy.GetParameterAsText(0)
 featureclasses = arcpy.ListFeatureClasses()
 for fc = in featureclasses:
 print (fc)
 def getParameterInfo(self):
 """Define parameter definitions"""
 params = None
 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."""
 return
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 30, 2020 at 21:06
5
  • 1
    Did you try returning something for getParameterInfo? pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/… Commented Jan 30, 2020 at 21:18
  • So, are you saying that because in my code, it says params = None, it returns nothing? Should I change it to 0 then? Commented Jan 30, 2020 at 21:26
  • The parameter need to be a path to a filename (initially, geodatabase filename.) What datatype should I choose for that? Commented Jan 30, 2020 at 21:35
  • You said that you "have been posting similar questions recently". Please always include links to any GIS SE questions that you mention in a new question so that potential answerers do not have to go looking for them before deciding whether this is actually a non-duplicate question. Commented Jan 30, 2020 at 22:03
  • Have you reviewed Defining parameters in a Python toolbox? Commented Jan 30, 2020 at 22:04

1 Answer 1

2

I suggest you look at the Python Toolbox documentation, particularly:

Your code was not working because:

  • your getParameterInfo method was returning None instead of a list of Parameter definitions
  • Your getParameter method will never get called as it's not part of the python toolbox API
  • Your execute method did nothing.

Here's a working example

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 = [Report]
class Report(object):
 def __init__(self):
 """Define the tool (tool name is the name of the class)."""
 self.label = "Tool"
 self.description = ""
 self.canRunInBackground = True
 def getParameterInfo(self):
 # Define parameter definitions
 params = []
 # First parameter
 param0 = arcpy.Parameter(
 displayName="Input workspace",
 name="in_workspace",
 datatype="DEWorkspace",
 parameterType="Required",
 direction="Input")
 params.append(param0)
 return params
 def execute(self, parameters, messages):
 """The source code of the tool."""
 arcpy.env.workspace = parameters[0].valueAsText
 featureclasses = arcpy.ListFeatureClasses()
 for fc in featureclasses:
 messages.addMessage(fc)
answered Jan 31, 2020 at 4:38
1
  • Thank you, but I just realized I have been barkin at the wrong tree. All this time I was thinking I was supposed to make Python toolbox, but actually I am supposed to make a script toolbox... Thank you tho! Commented Jan 31, 2020 at 22:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.