2

I am making a Python Toolbox for ArcGIS Pro. The main tool in the toolbox needs to have 5 radio buttons: Users can select any number of options (from 0 to 5).

Is it possible to group or cluster the radio buttons in a single dialog box? Further, since the parameters are optional inputs, is it possible to collapse the dialog box under a drop-down list? Toolbox Code, and ESRI-Interface

Here is the code from the .pyt file, shown in the screenshot above:

# -*- coding: utf-8 -*-
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 = "PDF Toolbox"
        self.alias = "Toolbox of PDFs"
        self.tools = [GhostScriptCompress]

class GhostScriptCompress(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Ghostscript PDF Compression Tool"
        self.description = "Compresses large PDFs using Ghostscript"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions."""
        inPDF = arcpy.Parameter(displayName="Input PDF Document",
                                name="outCompiledName",
                                datatype="DEFile",
                                parameterType="Required",
                                direction="Input")
                
        screen = arcpy.Parameter(displayName="Ghostscript 'screen' Compression",
                                 name="gsCompress_screen",
                                 datatype="GPBoolean",
                                 parameterType="Optional",
                                 direction="Input")
        ebook = arcpy.Parameter(displayName="Ghostscript 'ebook' Compression",
                                name="gsCompress_ebook",
                                datatype="GPBoolean",
                                parameterType="Optional",
                                direction="Input")
        printer = arcpy.Parameter(displayName="Ghostscript 'printer' Compression",
                                  name="gsCompress_printer",
                                  datatype="GPBoolean",
                                  parameterType="Optional",
                                  direction="Input")
        prepress = arcpy.Parameter(displayName="Ghostscript 'prepress' Compression",
                                   name="gsCompress_prepress",
                                   datatype="GPBoolean",
                                   parameterType="Optional",
                                   direction="Input")
        default = arcpy.Parameter(displayName="Ghostscript 'default' Compression",
                                  name="gsCompress_default",
                                  datatype="GPBoolean",
                                  parameterType="Optional",
                                  direction="Input")
        
        params = [inPDF, screen, ebook, printer, prepress, default]
        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."""
        for param in parameters:
            arcpy.AddMessage(f"Parameter ValueAsText: {param.valueAsText}")
            arcpy.AddMessage(f"Parameter Value: {param.value}")
            arcpy.AddMessage(f"Parameter Type: {type(param)}")
            arcpy.AddMessage("-----------------------")
        return
4

Add a category to the parameters that you want to group. For example

screen = arcpy.Parameter(
    displayName="Ghostscript 'screen' Compression",
    name="gsCompress_screen",
    datatype="GPBoolean",
    parameterType="Optional",
    direction="Input",
    category="Compression",
)
ebook = arcpy.Parameter(
    displayName="Ghostscript 'ebook' Compression",
    name="gsCompress_ebook",
    datatype="GPBoolean",
    parameterType="Optional",
    direction="Input",
    category="Compression",
)
1
3

I used @Mark Bryant's "category" answer/suggestion, coupled with using a "multiValue" parameter-type, instead of a bunch of individual parameter types. Screenshot shows the updated .pyt file, and two ArcGIS Pro views of the tool in the Geoprocessing pane: One collapsed, one expanded.

enter image description here

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.