in arcgis Pro if we want to do more complex processing or control how operations are executed we can create a python script tool so how do we do this well we've got our project here and if we go to the catalog window and go to toolboxes and then right click and select new python toolbox so we'll give the toolbox a name and then save it so we've now got an empty toolbox with an undefined script in there so we need to decide what we want this tool to do so in this project we've got a
layer a points layer and we need to buffer it based on an attribute field but only if the value is above a certain threshold so a user-defined threshold so this is a little bit more than what the standard geoprocessing buffer tool will do so ideal for a python script so you know something we can configure so the first thing we need to do is create our python code so to do this go on to the toolbox that we've just created and then right click on the script and edit the script will open in whatever you
have registered as your python editor I'm using visual studio code which is free but you can use anything even Notepad so the default code has already been added and we just need to fill in the functions to get our script to work so we cannot see how this can change things so if we go and change the label for example so we're going to change the label uh of the script and then we will save and then refresh the toolbox and we can see the label has now changed and in this way you can make
edits to your script and see those changes reflected in the toolbox real time so there are two functions of node here there's get parameter info and execute so if we look at get parameter info if we want to get information from the user and get the user to Define things then this is where we will do it so what I'm going to do is I'm going to take some code that I've already written and just paste it in here and if we have a look at this code what we'll see here is we've got four
pieces of info that we want to obtain from the user art Kai is the arcgis package that allows us to access the geoprocessing tool and many other GIS tasks and that package has already been imported at the top so if we just save and refresh this to see how those four pieces of inflow are reflected in the form so if we double click on the script to open the tool we can see we've now got the four items in the form waiting for import and if we look at the first one here with the display
name is the label that'll appear above each particular item and then the data type defines what we actually want the user to fill in so this first one is asking for a feature layer so it will create a drop down window for that listing all the items from the content to pay the next item is a field so that's going to be name of the field we're going to use to get the values for buffering then we have the threshold this is a double so that means we want the user to fill in a number
that includes that can includes decimals and then finally it's going to be the output location where the buffered feature layer is going to be saved to having defined the get parameter info function we can scroll down to the execute this is where we're going to put the code to actually do the processing so I'm just going to paste in code I've already written and the first part of the code we've got here is just to get those values that we Define in get parameter info just to get those into variables so the next part we'll
see we've got this feature make feature layer and this is making an in-memory feature layout for the feature class to buffer and this is based on a query and that query is only features that are greater than the fresh threshold and next we have ADD message and that prints out the number of features that will satisfy the query and you can use add a message to print any messages you want to the tool and finally we're going to buffer the layer for the features that do satisfy that query so if we save that and then
we'll go to the project and then we'll actually um we can actually run that the tool and we can see the results of running the tool and we'll get this buffered layer is the output and we can also see if we look at the messages from the tool run those arcpi dot add messages and that is a brief overview of python toolboxes and python toolboxes are completely self-contained files so they can easily be shared