3

I was wondering if there is a way I could easily include three parameters into a box (red box in the example) and so when there are a lot of inputs it's easier for a user to spot what data belongs to what sets of inputs.

Is there a way to give a title to the box ("Summary text" in red in the example) as well? In the example below, for example, I want to include param0, param1 and param2 into a box.

I'm hoping there is something built into arcpy rather than using third-party libraries.

import arcpy, os

class Toolbox(object):
    def __init__(self):
        self.label = "Toolbox"
        self.alias = ""
        self.tools = [Tool]
class Tool(object):
    def __init__(self):
        self.label = ""
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        param0 = arcpy.Parameter(
            datatype = "Folder", direction = "Input",
            parameterType = "Required", name = "Summary_1",
            displayName = "Field 1")

        param1 = arcpy.Parameter(
            datatype = "String", direction = "Input",
            parameterType = "Required", name = "Summary_2",
            displayName = "Field 2")
        param1.type = "ValueList"
        param1.filter.list = ["Item 1", "Item 2", "Item 3"]

        param2 = arcpy.Parameter(
            datatype = "File", direction = "Output",
            parameterType = "Required", name = "Summary_3",
            displayName = "Field 3")

        param3 = arcpy.Parameter(
            datatype = "Boolean", direction = "Input",
            parameterType = "Optional", name = "Date_1",
            displayName = "Replace Date?")

        param4 = arcpy.Parameter(
            datatype = "String", direction = "Input",
            parameterType = "Optional", name = "Date_2",
            displayName = "Enter Date to replace")        

        params = [param0, param1, param2, param3, param4]
        return params


    def execute(self, parameters, messages):
        return

Box with a title ("Summary text")

3

As per @Alex's answer, specify the category for your input parameters:

param.category = "Category text"

Then follow the steps I outlined in my previous answer: Controlling Categories in Script Validation Tools - Expanding Groups By Default to display the category expanded by default.

Then on line 439 of your custom .xsl file use some inline CSS styling to add a border.

Change:

STYLE="cursor:hand;" border="1" bordercolor="buttonface" 

To

STYLE="cursor:hand;border-collapse: collapse;border: 1px solid black;" 

You can play around with border thickness (i.e 2px) and border colour (or any other CSS styling you like).

Then again as per @Alex's answer, add the stylesheet property to point to the modified .xsl file:

class Tool(object):
    def __init__(self):
        self.label = ""
        self.description = ""
        self.canRunInBackground = False
        self.stylesheet = r"Path\to\MyCustom.xsl"

Voila:

enter image description here

3

I think you are looking for category for your input parameters.

Just add

param.category = "Summary text"

for each input parameter and then your tool UI would look like this:

enter image description here

However, mind that by default:

Categories are always shown after noncategorized parameters

However, it's possible to alter this by following the steps outlined in this answer: Controlling Categories in Script Validation Tools - Expanding Groups By Default. The instructions would differ in the last step as you are working with the Python toolbox, not the script tool.

In the source code, add the stylesheet property to point to the modified .xsl file:

class Tool(object):
    def __init__(self):
        self.label = ""
        self.description = ""
        self.canRunInBackground = False
        self.stylesheet = r"C:\GIS\MdDlgContent.xsl"

Then refresh the toolbox in ArcMap and open the tool. The category should be expanded by default (tested myself on 10.5).

  • Thanks Alex, I was hoping for a box, but this may be another way of looking at this. By default the categories are collapsed which can be confusing for the user where to input. Is there a way i can control the collapse feature of category so it's not collapsed by default? – Curtis Aug 6 '17 at 17:00
  • Sorry, @Curtis, the standard Python toolbox functionality will only take you this far. If you have time to learn a new framework, take a look at PyQT, me and other people were able to create tools with custom UI that could be run from ArcGIS Desktop interface – Alex Tereshenkov Aug 6 '17 at 18:22
  • this may seem possible according to this thread: gis.stackexchange.com/questions/226569/… – Curtis Aug 6 '17 at 19:59
  • But my stylesheet is greyed out, and can't change the default stylesheet in the toolbox – Curtis Aug 6 '17 at 20:00
  • @Curtis, good catch. I thought this is only possible with the script toolbox, but apparently it works even with Python toolboxes. I've updated my answer and tested, it works. – Alex Tereshenkov Aug 6 '17 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.