Parameter corruption in new atbx toolbox format

886
4
Jump to solution
08-29-2022 05:21 PM
isburns
New Contributor III

I converted a working toolbox with python script tools from the tbx format to the new atbx format and experienced behavior where a tool parameter was not being populated correctly. I was able to troubleshoot and determine when the parameter is populated correctly and when it is not. The difference occurs in the in the JSON type files tool.content and tool.content.rc that can be accessed through 7-Zip (or other archive utility). I'm guessing it relates to the "loading/opening of a toolbox with many tools, as well as the access of those tools' properties and parameters, when a particular tool is opened" discussed here.

The parameter has a data type of String and a Filter of Value List, and is used to list the layers in the map that pass validation. For troubleshooting, I stripped everything down to remove the validation and simply populate the parameter with all layers inside initializeParameters of the ToolValidator.

def initializeParameters(self):
    # Customize parameter properties. 
    # This gets called when the tool is opened.
    import os

    upd_list = []
    project = arcpy.mp.ArcGISProject("CURRENT")
    m = project.activeMap
    for lyr in m.listLayers():
        upd_list.append(lyr.name)
    self.params[0].filter.list = upd_list
            
    return

Pretty basic stuff. However, when you open tool, the parameter is sometimes populated with only blank entries. See below.

isburns_1-1661816722737.png

After opening the tool with an active map view window open it fails to populate, if you open the tool properties and inspect the Value List it should have the list of layers from the map view. To get the tool working, I enabled the Multiple values checkbox of the parameter, reopened the tool and the layers were all listed, then disabled the Multiple values checkbox again, and the layers were still listed properly. However the parameter breaks again if you add more layers to the map.

It seems like the performance improvements they tried to implement actually end up breaking functionality  (validation/filtering of layers in map before populating a parameter with them) that I'm not aware of being offered in another manner. The parameter items seem to be cached in the tool.content and tool.content.rc files (see below) and refreshing the toolbox doesn't seem to rebuild the cache. This makes atbx toolboxes unsuitable for sharing.

The tool.content file is below. In the file from a tool with the parameter populated,  the parameter has a domain property with items reflecting the layers populated in initializeParameters.

{
    "type": "ScriptTool",
    "displayname": "$rc:title",
    "app_ver": "13.0",
    "product": "100",
    "params": {
        "list_of_layers": {
            "displayname": "$rc:list_of_layers.title",
            "datatype": {
                "type": "GPString"
            },
            "domain": {
                "type": "GPCodedValueDomain",
                "items": [
                    {
                        "value": "aspect.tif",
                        "code": "$rc:list_of_layers.domain.aspect.tif"
                    },
                    {
                        "value": "slope.tif",
                        "code": "$rc:list_of_layers.domain.slope.tif"
                    },
                    {
                        "value": "fl_down.tif",
                        "code": "$rc:list_of_layers.domain.fl_down.tif"
                    }
                ]
            }
        }
    }
}

The tool.content.rc file is below and has some example layers listed that were included in the parameter and also refer back to the contents of the tool.content file.

{
    "map": {
        "list_of_layers.domain.aspect.tif": "aspect.tif",
        "list_of_layers.domain.fl_down.tif": "fl_down.tif",
        "list_of_layers.domain.slope.tif": "slope.tif",
        "list_of_layers.title": "List of Layers",
        "title": "Example"
    }
}

I've attached the toolbox that worked for me after I toggled the Multiple values checkbox in the Parameters tab of the tool properties to force the rebuild of the tool.content and tool.content.rc files. Unless you create layers with the names from above, the tool won't populate the layer names form the map.

Is this a known bug/limitation? Are there plans to fix this? Are there any other ways to filter and validate what  layers from a map will be included in a parameter?

0 Kudos
1 Solution

Accepted Solutions
DrewFlater
Esri Regular Contributor

@isburns Appreciate you posting about this and including your sample toolbox. 

We've reviewed the toolbox, debugged the problem, and made a fix in our development builds of ArcGIS Pro 3.1. To be clear, to get your sample toolbox to work, I had to clear the string parameter filter list in the Parameter properties page, click OK, then the tool would work going forward (again, in ArcGIS Pro 3.1). 

If you reopen the Parameter properties page again, you'll see that the UI again lists the items that were previously seen when the tool was opened and Initialize Parameters ran. However, these will not interfere and when the tool opens it will always get the dynamic filter list applied from the code in Initialize Parameters. 

We will evaluate if this fix is safe to backport to a Pro 3.0 patch after it has stabilized in our development versions. 

View solution in original post

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

When you say "converted", did you copy the working tool into the *.atbx?

I haven't had issues with custom python tool conversion as of yet, so I just want to clarify whether it is the "conversion" process or the type of the original python toolbox/tool


... sort of retired...
0 Kudos
isburns
New Contributor III

By converted, I meant right-click to copy the tool from the existing toolbox and then right-click on the new atbx toolbox and paste. However, for troubleshooting purposes, I created a new atbx toolbox and a new tool in that toolbox. The new tool had a single parameter and a Python script that is as simple as you can get. "Parameter corruption" may not be the best title for this post, but at the very least a string parameter populated by a value list that is set in initializeParameters is not working properly.

Also, my ArcGIS Pro is up-to-date, this was all using version 3.0.1.

0 Kudos
DrewFlater
Esri Regular Contributor

@isburns Appreciate you posting about this and including your sample toolbox. 

We've reviewed the toolbox, debugged the problem, and made a fix in our development builds of ArcGIS Pro 3.1. To be clear, to get your sample toolbox to work, I had to clear the string parameter filter list in the Parameter properties page, click OK, then the tool would work going forward (again, in ArcGIS Pro 3.1). 

If you reopen the Parameter properties page again, you'll see that the UI again lists the items that were previously seen when the tool was opened and Initialize Parameters ran. However, these will not interfere and when the tool opens it will always get the dynamic filter list applied from the code in Initialize Parameters. 

We will evaluate if this fix is safe to backport to a Pro 3.0 patch after it has stabilized in our development versions. 

0 Kudos
isburns
New Contributor III

@DrewFlater Thanks for following up and posting the (future) solution. 

0 Kudos