Select to view content in your preferred language

Toolbox properties : the *.atbx revisited

75
0
5 hours ago
Labels (1)
DanPatterson
MVP Esteemed Contributor
0 0 75

I prefer the custom toolboxes since you can screen grab the tool properties dialog.  Gathering the text information is a bit of a drag, so I have included the script that allows you to do this easily and/or incorporate it into your own toolboxes.

 

Start with a toolbox, its toolset(s) and tools.

toolbox_props_00.png

 

 

 

 

 

Here is a tool with its input parameter.  This one is to document *.atbx toolboxes.

toolbox_props_0.png

 

 

 

The results of the tool are sent to the messages which can be copies to the clipboard and pasted in your text processor etcetera.

toolbox_props_1.png

 

 

 

 

 

 

 

 

 

 

Here is the sample output in a text processor.

toolbox_props_2.png

 

 

 

 

 

 

Now in custom toolboxes, you fill in the parameters in a dialog.  You can follow the various options below

toolbox_props_3.png

 

 

Here is a sample tool.

toolbox_props_4.png

 

 

 

 

 

 

 

 

 

 

 

The general parameters are shown below.

toolbox_props_5.png

 

 

 

 

 

Code executation can be embedded or stored in a location relative to the toolbox itself.  That can be in the same folder or in another folder relative to the toolbox.

toolbox_props_6.png

 

 

 

 

 

 

You can provide validation within the dialog, making it easier to keep your code less cluttered or if your validation is simple or non-existent.

toolbox_props_7.png

 

 

 

 

 

 

Similarly, you can specify an environment variables within the dialog.

toolbox_props_8.png

 

 

 

 

 

 

 

============================

Now if I run the atbx info tool, you get the following results.

atbx info
=====================
Tool Path

C:\arcpro_npg\arcpro_36\npg_36\npg_36.atbx\atbxInfo
=====================
Parameters

toolbox path     C:\arcpro_npg\arcpro_36\npg_36\npg_36.atbx
=====================
Messages

Start Time: June 16, 2026 9:00:03 PM

--------
Running ... C:\arcpro_npg\arcpro_36\scripts_npg_36\atbx_info.py
--------

----
Toolbox : C:\arcpro_npg\arcpro_36\npg_36\npg_36.atbx
----

Property     Value
------------------
alias        npg36
--Tool                     Toolset
  FeatureVerticesToPoints  Featureclass tools
  atbxInfo                 Toolbox properties
  fcToGeo                  Featureclass tools
  fcTonpz                  NumPy tools
  npzTofc                  NumPy tools

Tools and Properties
--Tool : FeatureVerticesToPoints
--Toolset : Featureclass tools
  type  : ScriptTool
  displayname  : feature vertices to points
  script_file  : C:\arcpro_npg\arcpro_36\scripts_npg_36\feature_vertices_to_points.py
  description  : Convert poly* features to vertices.
  product_code  : 100
--Parameters
  name : point_type
  display name : point type
  direction : Input
  data type : String
  parameter type : Required
  enabled : True
  category : None
  symbology : None
  multi-value : False

Tools and Properties
--Tool : atbxInfo
--Toolset : Toolbox properties
  type  : ScriptTool
  displayname  : atbx info
  script_file  : C:\arcpro_npg\arcpro_36\scripts_npg_36\atbx_info.py
  description  : acquire toolbox info
  product_code  : 100
--Parameters
  name : toolbox_path
  display name : toolbox path
  direction : Input
  data type : File
  parameter type : Required
  enabled : True
  category : None
  symbology : None
  multi-value : False

Tools and Properties
--Tool : fcToGeo
--Toolset : Featureclass tools
  type  : ScriptTool
  displayname  : featureclass to Geo
  script_file  : C:\arcpro_npg\arcpro_36\scripts_npg_36\featureclass_to_Geo.py
  description  : Convert a featureclass to a Geo array.
  product_code  : 100
--Parameters
  name : input_features
  display name : input features
  direction : Input
  data type : Feature Layer
  parameter type : Required
  enabled : True
  category : None
  symbology : None
  multi-value : False

Tools and Properties
--Tool : fcTonpz
--Toolset : NumPy tools
  type  : ScriptTool
  displayname  : featureclass to npz
  script_file  : C:\arcpro_npg\arcpro_36\scripts_npg_36\featureclass_to_npz.py
  description  : Convert a featureclass to a numpy *.npz file.
  product_code  : 100
--Parameters
  name : npz_filename
  display name : npz filename
  direction : Input
  data type : String
  parameter type : Required
  enabled : True
  category : None
  symbology : None
  multi-value : False

Tools and Properties
--Tool : npzTofc
--Toolset : NumPy tools
  type  : ScriptTool
  displayname  : npz to featureclass
  script_file  : C:\arcpro_npg\arcpro_36\scripts_npg_36\npz_to_featureclass.py
  description  : Convert a numpy *.npz file to a featureclass.
  product_code  : 100
--Parameters
  name : output_fc
  display name : output featureclass
  direction : Output
  data type : Feature Class
  parameter type : Required
  enabled : True
  category : None
  symbology : None
  multi-value : False
Succeeded at June 16, 2026 9:00:04 PM (Elapsed Time: 0.68 seconds)

 

Here is the code

# -*- coding: utf-8 -*-
"""
@author: dan_patterson
"""

import sys
import arcpy
from arcgisscripting._arcgisscripting import _utbx

pth_ = arcpy.GetParameterAsText(0)  # the path to the toolbox
script = sys.argv[0]  # print this should you need to locate the script

def toolbox_info(t_box):
    """Return toolbox information.

    Parameters
    ----------
    t_box : toolbox in *.atbx format

    Example
    -------
    t_box = "C:/temp/npGeom_32.atbx"
    """
    def _hdr_(hdr_n):
        """Format the header."""
        return "{{:<{}s}}".format(hdr_n) + "  {!s:<}"

    t_box = t_box.replace("\\", "/")
    t_props = _utbx.getToolboxProps(t_box, "*")
    t_keys = sorted(list(t_props.keys()))
    hdr_n = max([len(i) for i in t_keys])
    frmt0 = _hdr_(hdr_n)
    msg = frmt0.format("Property", "Value") + "\n" + ("-")*(hdr_n + 7)
    z0 = ['name', 'display name', 'direction', 'data type', 'parameter type',
          'enabled', 'category', 'symbology', 'multi-value']
    keys0 = [i for i in t_keys if i != 'tools']
    keys1 = 'tools' if 'tools' in t_keys else None
    
    for k in keys0:  # toolbox properties
        v = t_props[k]
        msg += "\n" + frmt0.format(k, v)
        if keys1:  # `tool` properties
            v = t_props[keys1]
            v_keys = sorted(list(v.keys()))
            hdr_1 = max([len(i) for i in v_keys])
            frmt1 = _hdr_(hdr_1)
            msg += "\n" + frmt1.format("--Tool", "  Toolset")
            for k1 in v_keys:
                v1 = v[k1]
                msg += "\n  " + frmt1.format(k1, v1)
            for k1 in v_keys:
                pth = "{}/{}".format(t_box, k1)
                t_0 = _utbx.getToolProps(pth, '*')
                tool_keys = list(t_0.keys())
                msg += "\n\nTools and Properties"
                msg += "\n--Tool : {!s:<}\n--Toolset : {!s:}\n".format(k1, v[k1])
                for k2 in tool_keys:
                    if k2 != 'params':
                        msg += "  {!s:}  : {!s}\n".format(k2, t_0[k2])
                    elif k2 == 'params':
                        for i in t_0['params']:
                            z1 = [str(j) if j != '' else 'None'
                                  for j in [i.name, i.displayName, i.direction,
                                  i.datatype, i.parameterType, i.enabled,
                                  i.category, i.symbology, i.multiValue]
                                  ]
                        msg += "--Parameters\n"
                        txt = "\n".join(["  {!s:<} : {!s:}".format(*j)
                                         for j in list(zip(z0, z1))])
                        # msg += "parameter"
                        msg += txt
                    else:
                        msg += "unknown"
        return msg

# -------

msg = toolbox_info(pth_)  # -- run

out_ = "\n--------\nRunning ... {}\n--------\n".format(script)
out_ += "\n----\nToolbox : {}\n----\n".format(pth_)
arcpy.AddMessage(out_)
arcpy.AddMessage(msg)

# ----------------------------------------------------------------------
# __main__ .... code section
if __name__ == "__main__":
    # print the script source name.
    print('\n{} in source script... {}'.format(__name__, script))
    # parameters here

So between screen grabs and the atbx info tool, your documentation is complete.

Tags (3)
Contributors
About the Author
Retired Geomatics Instructor (also DanPatterson_Retired). Currently working on geometry projects (various) as they relate to GIS and spatial analysis. I use NumPy, python and kin and interface with ArcGIS Pro.
Labels