Skip to content

toolbox

Parameters

Bases: list[Parameter]

Wrap a list of parameters and override the index to allow indexing by name

Source code in src/arcpie/toolbox.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Parameters(list[Parameter]):
    """Wrap a list of parameters and override the index to allow indexing by name"""
    @overload
    def __getitem__(self, key: SupportsIndex, /) -> Parameter: ...
    @overload
    def __getitem__(self, key: slice, /) -> list[Parameter]: ...
    @overload
    def __getitem__(self, key: str, /) -> Parameter: ...
    def __getitem__(self, key: SupportsIndex|slice|str, /) -> Parameter | list[Parameter]:
        if isinstance(key, str):
            _matches = [p for p in self if p.name == key]
            if not _matches:
                raise KeyError(key)
            if len(_matches) == 1:
                return _matches.pop()
            raise KeyError(f'{key} is used for multiple parameters')
        return self[key]

ToolABC

Bases: ABC

Source code in src/arcpie/toolbox.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class ToolABC(ABC):
    def __init__(self) -> None:
        self.label: str
        self.description: str
        self.category: str
        self._project: ArcGISProject|None = None

    @property
    def project(self) -> ArcGISProject | None:
        """Get the current project that the tool is running in if it exists (otherwise: None)"""
        if self._project is None:
            try:
                self._project = ArcGISProject('CURRENT')
            except Exception:
                pass
        return self._project

    def getParameterInfo(self) -> Parameters | list[Parameter]: return Parameters()
    def isLicensed(self) -> bool: return True
    def updateParameters(self, parameters: Parameters | list[Parameter]) -> None: ...
    def updateMessages(self, parameters: Parameters | list[Parameter]) -> None: ...
    def execute(self, parameters: Parameters | list[Parameter], messages: list[Any]) -> None: ...
    def postExecute(self, parameters: Parameters | list[Parameter]) -> None: ...

project property

Get the current project that the tool is running in if it exists (otherwise: None)