Select to view content in your preferred language

ArcGIS Pro Python Toolbox: Update parameters not working as expected in Model Builder

1081
0
08-20-2020 11:34 AM
SurendraPinjala
Emerging Contributor

I am working on a tool in Python toolbox, it has two parameters.
If I run this tool from toolbox, it is working fine.
If I add this tool to model builder and run the model, it not working as expected.

Problem is that if I update Input Value 1, then Input Value 2 is updated as expected. But if I update Input Value 2, then the value of Input Value 1 is not updated as expected.


Here is the code:

# -*- coding: utf-8 -*-

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

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


class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = ""
self.canRunInBackground = False

def getParameterInfo(self):
"""Define parameter definitions"""
params = []
param1 = arcpy.Parameter(
displayName="Input Value 1",
name="param1",
datatype="GPDouble", parameterType="Required", direction="Input")
param1.value = 1.0

param2 = arcpy.Parameter(
displayName="Input Value 2",
name="param2",
datatype="GPDouble", parameterType="Optional", direction="Input")

params = [param1, param2]
return params

def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True

def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""

if (parameters[0].altered and not parameters[0].hasBeenValidated):
parameters[1].value = parameters[0].value * 4

if (parameters[1].altered and not parameters[1].hasBeenValidated):
parameters[0].value = parameters[1].value / 4

return

def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return

def execute(self, parameters, messages):
"""The source code of the tool."""
return

Please help me to fix this issue.

0 Kudos
0 Replies