Wednesday, July 27, 2016

Creating Custom Tools

GIS Programming - Mod 10

This week we modified a script to create a custom tool and a toolbox.  We modified a stand-alone script to create a tool to perform the clip function on multiple features based on a single clip boundary file. We did this by adding the new script to the new toolbox we created, added a description and selected the "Store relative path names" option.  Next we set the tool parameters and the options that go along with them.  
Once the tool was prepared we went back into the script to make the adjustments that were required to take it from a stand-alone script to one that would work within ArcMap.  To do this we had to replace the hard-coded values in the script with parameters passed by the tool using arcpy.GetParameter () and adding the appropriate index value for each variable into the argument and replacing the print statements with arcpy.AddMessage () statements in a for loop.

To do this we followed these basic steps:
1.       Create a new toolbox in a location it can be selected along with the script.
2.       Add the stand-alone script to the toolbox.
3.       Add a Description and select the “Store relative path names” option.
4.       Select the script as the Script File.
5.       Run to make sure it works.
6.       Enter the parameters and their options in the Properties box of the tool
7.       Update the script to change hard-coded values with arcpy.GetParameters(#),  replacing # with the appropriate index value for that particular parameter.
8.       Update the script to change print statements to arcpy.AddMessage statements, making sure everything to be printing is inside the argument parenthesis and any commas are changed to the plus sign.
9.       Any variables that need to pass a string and use results from arcpy.GetParameter function must be converted to a string
10.   Verify “Store relative path names” option is checked in the tool’s Properties, then select the script and the toolbox and compress them to a zipped folder.

No comments:

Post a Comment