Friday, 31 January 2020

arcpy - Defining parameter descriptions for Python Toolbox help?


I'm trying to create some Python Toolboxes for our ArcMap application (e.g. MyTool.pyt)


I can see that the help text is defined with the classes self.description attribute.


However, once I run the program, and click into any of the parameter fields, the help/description text goes empty. I would like to be able to provide the description field for each parameter. How is this accomplished?


After some responses, I see that via the 'Item Description' right-click context menu there are many fields that may be populated. Is there a 'pythonic' way to do this? That is, just by embedding some attributes in the .pyt file classes?


For instance, in the .pyt toolbox definition you have the Toolbox class:


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 = "My Toolbox"
self.alias = ""

# List of tool classes associated with this toolbox
self.tools = [MyNiceTool]



class MyNiceTool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "My Tool Class"
self.description = """
A description that shows up in the help context side pane when the tool is launched.
"""
self.canRunInBackground = True


def rest_of_required_methods....

From the self.description string the Tool dialog help window will display this text. However, what I am wanting to do is have a 'description' embedded in my code for each parameter also, so that when the tool is launched, and the user clicks into a parameter field, the parameter description is shown. If I were to do this using the 'Item Description' method referenced in the replies below, I would edit the fields Dialog Explanation under the Syntax section for each parameter... I guess.



Answer




I can see that the help text is defined with the classes self.description attribute.



This is where you are going wrong. In the help page Documenting a tool in a Python toolbox it says:




For Python toolboxes, the documentation for the toolbox and tools are stored in .xml files that are associated with the toolbox and tools by name. The help for each tool will be stored in a separate .xml file.



This means that you cannot set help text from within the .pyt file itself. This makes sense when you consider that the help text is not plain ASCII but rich text that can include formatting, bullets, and images.


Fortunately, Python supports for reading and writing XML, so you should be able to dynamically edit the help text from a separate script.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...