Select to view content in your preferred language

Support Tool Attributes in Python Toolboxes

118
1
Thursday
Status: Open
DavidSolari
MVP Regular Contributor

ArcGIS Pro 3.4 adds Attributes to the toolbox spec which adds extra options to script tools that were previously limited to default tools. The catch: these can't be added to Python Toolbox tools, at least not in any stable or documented way.

Please add support for Python Toolboxes. An "attributes" property on each tool that stores a list of attributes to set would align with how ATBX files store this info, something like:

class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = "My tool that edits the input data and costs credits."
        self.attributes = ["input_data_change", "credits"]

 

1 Comment
HaydenWelch

I think adding a Protocol and a Literal for the attributes would be a good idea:

from typing import Protocol, Literal
from arcpy import Parameter

ToolAttribute = Literal[
    'show_modification_banner',
    'add_to_map',
    'enable_undo',
    'show_credit_banner',
]

class ToolProto(Protocol):
    """Tool protocol for Python PYT tools"""
    
    def __init__(self) -> None: ... 
    def getParameterInfo(self) -> list[Parameter]: ...
    def isLicensed(self) -> bool: ...
    def updateParameters(self, parameters: list[Parameter]) -> None: ...
    def updateMessages(self, parameters: list[Parameter]) -> None: ...
    def execute(self, parameters: list[Parameter], messages: list) -> None: ...
    def postExecute(self, parameters: list[Parameter]) -> None: ...


# Alternative inheritable base class 
class ToolBase:
    """Tool base for Python PYT tools"""
    
    def __init__(self) -> None:
        self.description: str | None = None
        self.label: str | None = None
        self.category: str | None = None
        self.attributes: list[ToolAttribute] | None = None
        
    def getParameterInfo(self) -> list[Parameter]: ...
    def isLicensed(self) -> bool: ...
    def updateParameters(self, parameters: list[Parameter]) -> None: ...
    def updateMessages(self, parameters: list[Parameter]) -> None: ...
    def execute(self, parameters: list[Parameter], messages: list) -> None: ...
    def postExecute(self, parameters: list[Parameter]) -> None: ...

 

Could add docstrings to the Tool methods as well to make it easier to see