Skip to main content
deleted 19 characters in body; edited tags; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Updating tool´s ValueTable parameter of ArcPy Python Toolbox tool

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.

Do you have any tips how toHow do I make the ValueTable work correctly?

Updating tool´s ValueTable parameter

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.

Do you have any tips how to make the ValueTable work correctly?

Updating ValueTable parameter of ArcPy Python Toolbox tool

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.

How do I make the ValueTable work correctly?

added 67 characters in body
Source Link
jonlew
  • 451
  • 2
  • 12

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.

Do you have any tips how to make the ValueTable work correctly?

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.

Do you have any tips how to make the ValueTable work correctly?

Source Link
jonlew
  • 451
  • 2
  • 12

Updating tool´s ValueTable parameter

I have a shapefile and I want to calculate multiple fields using the GP ValueTable parameter.

The script loads field names from a layer, then I should delete rows I don´t want to calculate and then I should write values to the second column to be filled in selected fields. Then it should arcpy.CalculateField.

But I am stuck at parameter settings. The script lies in the Python toolbox.

def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("in_layer", "Vrstva", "GPFeatureLayer")
    param1 = parameter("field_values", "Atributova pole a hodnoty k vyplneni", "GPValueTable")

    param1.parameterDependencies = [param0.name]
    param1.columns = [["String", "Pole"], ["String", "Hodnota"]]

    params = [param0, param1]
    return params

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].value:
        v_list = []
        fld_names = [f.name for f in arcpy.ListFields(parameters[0].value)]

        for fld in fld_names:
            v_list.append([fld, ""])
            del fld

        parameters[1].value = v_list

        del fld_names
        del v_list

    return

When I select a layer in the tool, it populates field names (great!) and it looks like this: Tool parameters

But...

  1. If I want to delete some rows using the button on the right side, it does nothing, it does not delete the row. It just seems that it somehow "refreshes" the value table.
  2. If I want to write a value to the second column, it lets me but after hitting enter or clicking anywhere else it erases the written value and sets nothing, empty value again. It does not hold what I am writing there.