Friday, July 31, 2015

Module 10 - Creating Custom Tools

This week was a double work week, as we were working on our final script projects as well as Module 10. Luckily the module was simple and straightforward...as long as you got all your syntax and parameters put in right! We actually did a little toolbox and script tool creation earlier this semester, but it was good to go through it again as it is useful knowledge.

For the lab I created a new toolbox in my Module 10 folder, added a stand-alone script that was already written, and then worked on setting the parameters in the tool dialog and in the script so when the tool is selected it will run correctly. The tool and script clips multiple features at the same time in ArcMap. The trickiest part was setting the tool parameters in ArcMap within the tool properties window. Thinking through which parameters were input and output (this one got me-"output file location" is actually an input), setting the correct data type, and making sure I filled in all the necessary values. After taking note of the order of the parameters, it was back to the script to change the hard-coded file paths to arcpy.GetParameter() with the corresponding parameter number from the tool inserted as the argument. This allows the script to read the parameters from the tool. Finally the print statements were changed to AddMessage function so the results would be printed to the Results window in ArcMap when the tool is run.

The only real hiccup was realizing my parameter error with input and output and a couple syntax errors of putting an 's' on the end of AddMessage. After those were fixed, the script tool ran perfectly.


Script tool window with correct parameters set through the tool properties. 

Results window showing successful clipping of multiple features at once through new script tool. 

No comments:

Post a Comment