toolbox
Classes:
| Name | Description |
|---|---|
Done |
An Empty Output parameter that can be used to signal that a tool has completed in Model Builder |
Double |
Simple Double/Float parameter with default and filter passthroughs |
FeatureLayer |
Simple Feature Layer parameter with filter and default passthroughs |
FilePath |
Simple filepath input with default and filter passthroughs |
Folder |
Simple Feature Layer parameter with filter and default passthroughs |
Integer |
Simple Integer number parameter with default and filter passthroughs |
Parameter |
|
Parameters |
Wrap a list of parameters and override the index to allow indexing by name |
String |
Simple string input parameter with filter options and default passthrough |
StringList |
Simple string list with default and filter passthroughs |
Toggle |
Simple toggle button with a name and default state |
Tool |
|
ToolABC |
|
ToolboxABC |
|
Functions:
| Name | Description |
|---|---|
safe_load |
Safely load in tools to a toolbox placing all failed imports in a |
toolify |
Convert a typed function into a tool for the specified Toolbox class |
Attributes:
| Name | Type | Description |
|---|---|---|
ParameterTypeMap |
|
ParameterTypeMap = dict[str, tuple[ParameterDatatype | list[ParameterDatatype] | Parameter, Callable[[Parameter], Any]]]
module-attribute
¶
Done
¶
Bases: Parameter
An Empty Output parameter that can be used to signal that a tool has completed in Model Builder
Methods:
| Name | Description |
|---|---|
__init__ |
|
Source code in src/arcpie/toolbox.py
112 113 114 115 116 117 118 119 120 121 | |
__init__()
¶
Source code in src/arcpie/toolbox.py
114 115 116 117 118 119 120 121 | |
Double
¶
Bases: Parameter
Simple Double/Float parameter with default and filter passthroughs
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__name__ |
|
|
value |
|
Source code in src/arcpie/toolbox.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
__name__ = 'Parameter'
class-attribute
instance-attribute
¶
value = default
instance-attribute
¶
__init__(displayName, options=None, default=None, required=True, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
FeatureLayer
¶
Bases: Parameter
Simple Feature Layer parameter with filter and default passthroughs
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__name__ |
|
|
controlCLSID |
|
|
value |
|
Source code in src/arcpie/toolbox.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
__name__ = 'Parameter'
class-attribute
instance-attribute
¶
controlCLSID = '{60061247-BCA8-473E-A7AF-A2026DDE1C2D}'
instance-attribute
¶
value = default
instance-attribute
¶
__init__(displayName, options=None, default=None, required=True, name=None, allow_create=False, category=None)
¶
Source code in src/arcpie/toolbox.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
FilePath
¶
Bases: Parameter
Simple filepath input with default and filter passthroughs
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
value |
|
Source code in src/arcpie/toolbox.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
value = default
instance-attribute
¶
__init__(displayName, options=None, default=None, required=True, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Folder
¶
Bases: Parameter
Simple Feature Layer parameter with filter and default passthroughs
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__name__ |
|
|
value |
|
Source code in src/arcpie/toolbox.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
__name__ = 'Parameter'
class-attribute
instance-attribute
¶
value = default
instance-attribute
¶
__init__(displayName, options=None, default=None, required=True, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
Integer
¶
Bases: Parameter
Simple Integer number parameter with default and filter passthroughs
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__name__ |
|
|
value |
|
Source code in src/arcpie/toolbox.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
__name__ = 'Parameter'
class-attribute
instance-attribute
¶
value = default
instance-attribute
¶
__init__(displayName, options=None, default=None, required=True, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
Parameter
¶
Bases: Parameter
Methods:
| Name | Description |
|---|---|
__init__ |
|
Source code in src/arcpie/toolbox.py
20 21 22 23 24 25 26 27 28 29 30 31 | |
__init__(name=None, displayName=None, direction=None, datatype=None, parameterType=None, enabled=None, category=None, symbology=None, multiValue=None)
¶
Source code in src/arcpie/toolbox.py
21 22 23 24 25 26 27 28 29 30 31 | |
Parameters
¶
Bases: list[Parameter]
Wrap a list of parameters and override the index to allow indexing by name
Methods:
| Name | Description |
|---|---|
__contains__ |
|
__getitem__ |
|
get |
|
Source code in src/arcpie/toolbox.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
__contains__(key)
¶
Source code in src/arcpie/toolbox.py
101 102 103 104 105 106 107 108 | |
__getitem__(key)
¶
__getitem__(key: SupportsIndex) -> Parameter
__getitem__(key: slice) -> list[Parameter]
__getitem__(key: str) -> Parameter
Source code in src/arcpie/toolbox.py
79 80 81 82 83 84 85 86 87 | |
get(key, default=None)
¶
get(
key: SupportsIndex, default: _Default = None
) -> Parameter | _Default
get(
key: slice, default: _Default = None
) -> list[Parameter] | _Default
get(
key: str, default: _Default = None
) -> Parameter | _Default
Source code in src/arcpie/toolbox.py
95 96 97 98 99 | |
String
¶
Bases: Parameter
Simple string input parameter with filter options and default passthrough
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
value |
|
Source code in src/arcpie/toolbox.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
value = default
instance-attribute
¶
__init__(displayName, options=None, default=None, required=True, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
StringList
¶
Bases: Parameter
Simple string list with default and filter passthroughs
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
values |
|
Source code in src/arcpie/toolbox.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
values = defaults
instance-attribute
¶
__init__(displayName, options=None, defaults=None, required=True, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
Toggle
¶
Bases: Parameter
Simple toggle button with a name and default state
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
value |
|
Source code in src/arcpie/toolbox.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
value = default
instance-attribute
¶
__init__(displayName, default=False, name=None, category=None)
¶
Source code in src/arcpie/toolbox.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Tool
¶
Bases: ToolABC
Attributes:
| Name | Type | Description |
|---|---|---|
active_map |
Map | None
|
|
project |
Project | None
|
Get the current project that the tool is running in if it exists (otherwise: None) |
Source code in src/arcpie/toolbox.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
ToolABC
¶
Bases: ABC
Methods:
| Name | Description |
|---|---|
__init__ |
|
execute |
|
getParameterInfo |
|
isLicensed |
|
postExecute |
|
updateMessages |
|
updateParameters |
|
Attributes:
| Name | Type | Description |
|---|---|---|
category |
str | None
|
|
description |
str
|
|
label |
str
|
|
Source code in src/arcpie/toolbox.py
39 40 41 42 43 44 45 46 47 48 49 50 | |
category = None
instance-attribute
¶
description = self.__doc__ or 'No Descrption Provided'
instance-attribute
¶
label = self.__class__.__name__
instance-attribute
¶
__init__()
¶
Source code in src/arcpie/toolbox.py
40 41 42 43 | |
execute(parameters, messages)
¶
Source code in src/arcpie/toolbox.py
49 | |
getParameterInfo()
¶
Source code in src/arcpie/toolbox.py
45 | |
isLicensed()
¶
Source code in src/arcpie/toolbox.py
46 | |
postExecute(parameters)
¶
Source code in src/arcpie/toolbox.py
50 | |
updateMessages(parameters)
¶
Source code in src/arcpie/toolbox.py
48 | |
updateParameters(parameters)
¶
Source code in src/arcpie/toolbox.py
47 | |
ToolboxABC
¶
safe_load(tools, *, scope=None, reload_module=False)
¶
Safely load in tools to a toolbox placing all failed imports in a Broken Tools category
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
dict[str, list[str]]
|
A mapping of tool modules to tool files or tool classes in a module |
required |
scope
|
dict[str, Any]
|
The |
None
|
reload_module
|
bool
|
Reload the module after importing (default: False) |
False
|
Returns:
| Type | Description |
|---|---|
list[type[ToolABC]]
|
A list of tool classes |
Note
To isolate bugs in a large toolbox, it is reccomended that you use file/module level importing
with matching toolclass names (e.g. Tool.py -> class Tool) where the Tool mapping is:
Tools = {'tools': ['Tool.py']}
instead of:
Tools = {'tools.Tool': ['Tool']}
This allows the import to fail softly on a single tool instead of breaking imports for all other
toolclasses in that Tool.py module.
Any tools with errors will be placed in a Broken Tools category in the toolbox with the full
stack trace placed in its description field. The final component of the exception will be placed
at the end of the tool label for easy debugging.
Example
>>> # File import
>>> Tools = {
... # import matching class from named file in a submodule (tools)
... # where ToolFileA is ToolFileA.py with a class ToolFileA
... 'tools': ['ToolFileA', 'ToolFileB'],
...
... # Import explicit ToolClass from toolfile (MyTools.py)
... # NOT RECOMMENDED
... 'tools.MyTools': ['ToolClassA', 'ToolClassB'],
... }
>>> tools = safe_import(globals(), Tools)
Source code in src/arcpie/toolbox.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
toolify(*tool_registries, name=None, params=None, debug=False, logger=None)
¶
Convert a typed function into a tool for the specified Toolbox class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tool_registries
|
list[type[ToolABC]]
|
The tool registry lists to add this tool to |
()
|
name
|
str
|
The name of the tool |
None
|
params
|
ParameterTypeMap
|
A mapping of parameter names to Parameter types and a callable constructor that converts the parameter to the expected value for the function parameter. You can also pass a fully formed arcpy.Parameter object as the first item in the tuple instead of a simple type |
None
|
debug
|
bool
|
Print the converted arguments to the ArcGIS Pro message console (default: False) |
False
|
logger
|
Logger | None
|
An optional logger to use for logging all runs of the toolified tool |
None
|
Usage
>>> @toolify(
>>> TOOL_REGISTRY,
>>> name='PDF Exporter',
>>> params={
>>> 'project': ('DEFile', lambda p: Project(p.valueAsText)),
>>> 'outfile': ('DEFile', lambda p: Path(p.valueAsText))
>>> }
>>> )
>>> def export_pdf(project: Project|str='CURRENT', outfile: Path|str='out.pdf') -> None:
>>> ...
Source code in src/arcpie/toolbox.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |