Select to view content in your preferred language

Script Tool with Interactive Mouse Click as Parameter Input Example?

202
4
Jump to solution
2 weeks ago
Labels (1)
ewmahaffey
Occasional Contributor

Does anyone have an example script that can be used to build a script tool that has an interactive input from a mouse click event?  Basically I'm looking to build a simple tool that allows the user to click on the map, and the coordinates (or feature that's generated) at that location are used as input for the arcpy.analysis.Buffer tool. All the research I've done talks about using a Feature Set for interactive input, but I can't seem to find any good script examples so I can see how their connected.

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Notable Contributor

A simple example would be the old classic Clip and Ship from ArcGIS tutor which has a Script tool designed for use as a Geoprocessing Task in ArcGIS Server.  ArcMap however and based on Model Builder.
I think the data etc. can still be downloaded.
Geoprocessing service example: Clip And Ship—ArcGIS Server | Documentation for ArcGIS Enterprise

However if you would like to share your code so far and what you want to achieve, I'm sure someone could work your example.

A simplified example which may be of use.  After loading the script as a tool, set the first parameter 0 as Feature Set data type, direction Input and I believe you can control the geometry input type specifying a .lyrx file in the 'default' tab.  this link details setting this up Interactive feature input—ArcGIS Pro | Documentation

import arcpy 

# specify the point layer
feature_set = arcpy.GetParameter(0)

# output buffer 
out_loc = arcpy.GetParameterAsText(1)

# buffer
arcpy.analysis.Buffer(feature_set, out_loc, "100 meters")

 

View solution in original post

4 Replies
DavidPike
MVP Notable Contributor

A simple example would be the old classic Clip and Ship from ArcGIS tutor which has a Script tool designed for use as a Geoprocessing Task in ArcGIS Server.  ArcMap however and based on Model Builder.
I think the data etc. can still be downloaded.
Geoprocessing service example: Clip And Ship—ArcGIS Server | Documentation for ArcGIS Enterprise

However if you would like to share your code so far and what you want to achieve, I'm sure someone could work your example.

A simplified example which may be of use.  After loading the script as a tool, set the first parameter 0 as Feature Set data type, direction Input and I believe you can control the geometry input type specifying a .lyrx file in the 'default' tab.  this link details setting this up Interactive feature input—ArcGIS Pro | Documentation

import arcpy 

# specify the point layer
feature_set = arcpy.GetParameter(0)

# output buffer 
out_loc = arcpy.GetParameterAsText(1)

# buffer
arcpy.analysis.Buffer(feature_set, out_loc, "100 meters")

 

ewmahaffey
Occasional Contributor

Thanks David.  I had looked at the Interactive Feature Input page a few times, and from it learned how to setup the parameters in the script tool properties. I guess I'm just struggling with how to write the code to work with the parameters (the Feature Set parameter in particular). I've been building scripts all along that just run in straight Python.  Attaching them to a tool is new to me. I was able to get my tool to run if the coordinates are manually entered (i.e. arcpy.GetParameterAsText). Now I'm trying to change it to use the coordinates from a mouse click or from a feature that's generated. Unfortunately I can't share the script because it's on a disconnected network.

0 Kudos
DavidPike
MVP Notable Contributor

I've put a simple code example in.  NB it's 

arcpy.GetParameter(0)

rather than 

arcpy.GetParameterAsText(0)

Within the code, just treat it as if it were a feature class point layer thereafter.

ewmahaffey
Occasional Contributor

Thanks David.  I was able to get it working with the explanation you provided.  Setting the Feature Set to use the arcpy.GetParameter(0) along with the associated variable configuration in the script tool properties generated a feature class and feature within the default database. I was then able to have the Buffer geoprocessing tool use that f-class as input. I messed around with creating a layer file to be used as a template for the input point and output polygon symbology.  Thanks for the help!

feature_set = arcpy.GetParameter(0)

 

0 Kudos