Select to view content in your preferred language

Python Toolbox Toolset

5711
4
Jump to solution
06-10-2013 12:40 PM
DavidAllen
Frequent Contributor
Can someone post an example of how to configure and use the toolsets in a Python Toolbox?

The help barely mentions that this is even an option, and the only code example I can find is to set:
self.category = ???Toolset Name???

but when you have:
self.tools = [tool1, tool2]

I just get the regular tools listed in the toolbox without a toolset.

How do you tell it to put the tools into the category?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ShaunWalbridge
Esri Regular Contributor
I've create an example, example-toolbox.pyt that hopefully clarifies (also as a Github Gist😞

import arcpy
 
class Toolbox(object):
    def __init__(self):
        self.label = u'Example_Toolbox'
        self.alias = ''
        self.tools = [FirstTool, SecondTool, ThirdTool]
 
 
class FirstTool(object):
 
    def __init__(self):
        self.label = u'First Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Import"
 
    def getParameterInfo(self):
        return
 
    def execute(self, parameters, messages):
        pass
 
class SecondTool(object):
 
    def __init__(self):
        self.label = u'Second Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Export"
 
    def getParameterInfo(self):
        return
 
    def execute(self, parameters, messages):
        pass
 
class ThirdTool(object):
 
    def __init__(self):
        self.label = u'Third Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Export"
 
    def getParameterInfo(self):
        return
 
    def execute(self, parameters, messages):
        pass


You'll then have two categories within your toolbox: Export and Import, Import will contain one item and Export will contain two.

cheers,
Shaun

View solution in original post

4 Replies
ShaunWalbridge
Esri Regular Contributor
I've create an example, example-toolbox.pyt that hopefully clarifies (also as a Github Gist😞

import arcpy
 
class Toolbox(object):
    def __init__(self):
        self.label = u'Example_Toolbox'
        self.alias = ''
        self.tools = [FirstTool, SecondTool, ThirdTool]
 
 
class FirstTool(object):
 
    def __init__(self):
        self.label = u'First Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Import"
 
    def getParameterInfo(self):
        return
 
    def execute(self, parameters, messages):
        pass
 
class SecondTool(object):
 
    def __init__(self):
        self.label = u'Second Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Export"
 
    def getParameterInfo(self):
        return
 
    def execute(self, parameters, messages):
        pass
 
class ThirdTool(object):
 
    def __init__(self):
        self.label = u'Third Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Export"
 
    def getParameterInfo(self):
        return
 
    def execute(self, parameters, messages):
        pass


You'll then have two categories within your toolbox: Export and Import, Import will contain one item and Export will contain two.

cheers,
Shaun
BartłomiejStaroń
Occasional Contributor

How to create toolset in toolset? It is possibile?

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Sure, just embed '\' separators between the toolsets. Here's an example where the two "Export" tools will be in separate toolsets, nested underneath the parent (also on GitHub😞

import arcpy

class Toolbox(object):
    def __init__(self):
        self.label = u'Example_Toolbox'
        self.alias = ''
        self.tools = [FirstTool, SecondTool, ThirdTool]


class FirstTool(object):

    def __init__(self):
        self.label = u'First Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Import"

    def getParameterInfo(self):
        return

    def execute(self, parameters, messages):
        pass

class SecondTool(object):

    def __init__(self):
        self.label = u'Second Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Export\\GeoJSON"

    def getParameterInfo(self):
        return

    def execute(self, parameters, messages):
        pass

class ThirdTool(object):

    def __init__(self):
        self.label = u'Third Tool'
        self.description = u''
        self.canRunInBackground = False
        self.category = "Export\\TopoJSON"

    def getParameterInfo(self):
        return

    def execute(self, parameters, messages):
        pass
DavidAllen
Frequent Contributor
I've create an example, example-toolbox.pyt that hopefully clarifies (also as a Github Gist😞

You'll then have two categories within your toolbox: Export and Import, Import will contain one item and Export will contain two.

cheers,
Shaun



Aha! I found three references to adding the self.category but none said that it goes in the individual tool class rather than the toolbox class.
Perfectly understandable now.  Thanks!!
0 Kudos