AnsweredAssumed Answered

Issues with PythonToolbox

Question asked by TomGeo on Sep 11, 2020

After a while not coding Python in ArcGIS I get the feeling I am a bit rusty...

 

In ArcGIS Pro (2.5.1) I created a PytonToolbox and started to add parameters, namely DEWorkspace, GPMap, and DEFolder. While the workspace and map parameters work almost as expected, the folder parameter does not.

 

As an example here how I implemented one of the folder parameters:

lyr01 = arcpy.Parameter(
displayName = "LYR directory",
name = "lyrx_aju",
datatype = "DEFolder",
parameterType = "Optional",
direction = "Input",
category = "Updates"
)

 

The result of it is as expected a browse button with associated textbox. When I select a directory in the dialogue through the browse button than the name of the selected directory (not the path!) is shown in the textbox, just to disappear right after.

This behaviour makes it pretty hard to make a user understand there is a directory selected...

 

Then there is the part with the enabled property/method of the parameter object.

It does not matter the slightest if I add an

enabled = False

in the code snippet above or not. The control is always enabled.

Using the updateParameters function for the same purpose:

 

if parameters[0].value is not None:
        parameters[1].enabled = True
        parameters[2].enabled = True
else:
        parameters[1].enabled = False
        parameters[2].enabled = False

returns with a hidden parameter 1, but a visible, and enabled parameter 2. As soon as I select a value in parameter 0, parameter 1 is visualised and it is enabled.

 

Last but not least, if I run the tool, and there is nothing in the execute function than the return (it does not matter if there is something more in the execute function), then I am getting the message that the tool failed. The tool fails with error 000820:

 

The parameters need repair. --> The tool parameters have changed since the model was last updated. When a tool that is used in a model is modified, the model needs to be modified to recognize the tool as it exists now.

 

The suggested solution has sure enough the precision of a mass murderer... Some edits will be required on the model.

 

If I understand correctly then model means the pyt file... Problem is, I can do what ever I want to the code in the pyt file, it will not change the outcome of the tool run.

 

Does somebody has a solution for the problem with DEFolder, and the error 000820?

 

Best regards

Thomas

Outcomes