Hi all,
I'm wondering how to reorder my parameters in a scripting tool.
For example, I just added Parameter #10, but I want it to show up 3rd when the user opens the tool. Is this possible to do?
Thanks!
Solved! Go to Solution.
Assuming you are using a custom toolbox (*.tbx), right click your script in the toolbox and select "Properties", select the parameters tab and then right click on the parameter you want to move and select "Move up" or "Move down". And then change the parameter references in your code.
If you're actually using a Python Toolbox (*.pyt) then it's easier, just move the parameters around in your tool `getParameterInfo` method and then refer to the parameters by name using a dict or namedtuple
class Tool
etc...
def execute(self, parameters, messages):
parameters = {p.name: p for p in parameters}
# do something with parameters["some_name"]
# Or
from collections import namedtuple
class Tool
etc...
def execute(self, parameters, messages):
parameters = namedtuple('Parameters', (p.name for p in parameters))(*parameters)
# do something with parameters[0] or parameters.some_name
I also recommend voting for the following idea:
ArcGIS Pro Ideas - Make Python Toolbox parameters a namedtuple instead of a list
My understanding is that you need to move it to parameter#3 and then update all the references in you code to parameters[3] (or parameters[2])
Assuming you are using a custom toolbox (*.tbx), right click your script in the toolbox and select "Properties", select the parameters tab and then right click on the parameter you want to move and select "Move up" or "Move down". And then change the parameter references in your code.
If you're actually using a Python Toolbox (*.pyt) then it's easier, just move the parameters around in your tool `getParameterInfo` method and then refer to the parameters by name using a dict or namedtuple
class Tool
etc...
def execute(self, parameters, messages):
parameters = {p.name: p for p in parameters}
# do something with parameters["some_name"]
# Or
from collections import namedtuple
class Tool
etc...
def execute(self, parameters, messages):
parameters = namedtuple('Parameters', (p.name for p in parameters))(*parameters)
# do something with parameters[0] or parameters.some_name
I also recommend voting for the following idea:
ArcGIS Pro Ideas - Make Python Toolbox parameters a namedtuple instead of a list
Thanks for the response.
Unfortunately, that is exactly what I am trying to avoid; moving the parameters manually like that means I have to change every other reference. So #10-->3, #3-->4, #4-->5, etc.
I've been able to get around it partially by using categories, but that's not viable for everything.
I thought I saw something the other week about parameter order independent of its index position but I guess not. I'll leave this up for another day or so just in case and then mark you as the solution.
Thanks again