0

I am trying to write a Python code for creating a geoprocessing tool which will be added as a toolbox in ArcGIS Pro (v2.6).

The tool will

  • Ask for a "Target point feature" as input for the (X, Y) coordinates
  • Ask for a set of "Input point features" whose coordinates will be changed to the target's coordinates to stack together.
import arcpy

def move_points_to_target(target_feature, input_features):
    # Get the coordinates of the target feature
    with arcpy.da.SearchCursor(target_feature, ["SHAPE@XY"]) as cursor:
        for row in cursor:
            target_x, target_y = row[0]

    # Loop through each input feature and move it to the target location
    for feature in input_features:
        with arcpy.da.UpdateCursor(feature, ["SHAPE@XY"]) as cursor:
            for row in cursor:
                # Update the coordinates of the input feature to match the target location
                row[0] = (target_x, target_y)
                cursor.updateRow(row)


def parameterInfo(self):
    """Define parameter definitions"""
    # First parameter - Target Point Feature
    target_param = arcpy.Parameter(
        displayName="Target Point Feature",
        name="target_feature",
        datatype="DEFeatureClass",
        parameterType="Required",
        direction="Input"
    )

    # Second parameter - Input Point Features
    input_param = arcpy.Parameter(
        displayName="Input Point Features",
        name="input_features",
        datatype="DEFeatureClass",
        parameterType="Required",
        direction="Input",
        multiValue=True
    )

    return [target_param, input_param]


if __name__ == "__main__":
    # Get parameters from tool
    target_feature = arcpy.GetParameterAsText(0)
    input_features = arcpy.GetParameterAsText(1)

    # Call the function to move the points to the target location
    move_points_to_target(target_feature, input_features)

When I added it to my ArcGIS Pro toolbox, it does not ask for any inputs and the parameters seems to go back to default string.

I am just starting to learn how to make a geoprocessing tool.

What am I doing wrong?

In this image, you can see that tool does not ask for any inputs.

Also,

in this image you can see I cannot add parameters as input

3
  • 3
    You're confusing python toolboxes (*.pyt) with script tools in a regular toolbox (*.atbx or *.tbx). Script tools don't specify parameters in code, the parameters are set up in the toolbox settings (your last image). See pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/… Commented May 7, 2024 at 1:19
  • not really, it doesn't answer the question, just provdes a starting point. Commented May 7, 2024 at 2:09
  • @user2856 - The actual question is, literally, "What am I doing wrong?". I think you answered it correctly with your comment. Just needs to be fleshed out with a bit more detail/explanation on how parameters are handled between the two types of python tools/toolboxes. :-) Commented May 7, 2024 at 23:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.