I am in the midst of adding a new tool to Whitebox GAT, which is merely copy of a current tool with some minor modifications to suppress messages output by the tool upon completion. This tool's messages, which require clicking "OK" after it completes, is preventing the batch processing of thousands of files.

Has anyone successfully followed the instructions for adding a new plugin to Whitebox? I have followed the instructions to a 'T', checking the work several times, but the new tool doesn't seem to be loading correctly. In fact, after adding the new .jar file to the correct folder (plugins folder within the resources folder), Whitebox won't load at all.

Has anyone had similar problems? Is there a known issue or a way to get this to work?

  • Hi Tom, I know you finally found and answer to your problem. Would you post your solution so others can benefit? Thanks. – WhiteboxDev Aug 5 '14 at 14:22
  • Yes of course!! Very busy with prepping for my candidacy exams this week, but hopefully soon!!! – traggatmot Aug 5 '14 at 14:28
  • @WhiteboxDev, I borrowed liberally from our email correspondence. Let me know if this is a problem. Also, feel free to clarify anything - I'll add it to the answer. – traggatmot Aug 5 '14 at 23:26

This 1st part of this answer applied mostly to added a toolbox to whitebox using Java; the second part focuses on the somewhat similar, though much easier, processes that currently exists for adding tools using python scripts.

Plugin addition using Java

Following the instructions on the pdf hosted here will get you 99% of the way there. But after the following the instructions exactly, I could not load my tool. The problem comes down to a difference in the way you name your package in the java code for the tool. Step 9 in the instructions states:

First, if your new tools doesn’t reside within the same package (jar file) as the tool you just pasted the code from, you will need to alter the package statement on the first line; in the example from the image above, the MyTool class would need to have a first line that states, ‘package JohnLindsaysTools’ in reference to the JohnLindsaysTools.jar file that will be created when I compile my project.

This is referencing the part of the java code for the tool that is circled below:

enter image description here

I have found that writing the name of the eventual jar file (the name of the project - in my case Tom_Taggart_Tools) doesn't work - that this prevents proper WhiteBox GAT from seeing the compiled JAR file - it probably compiles incorrectly or something, not sure. Anyway, the fix is to simply write the first line as it is labeled in the picture - "package plugins". That will allow the tool to (correctly) compile in a manner which produces a .jar file that WhiteBox recognizes. I assume this works because it correctly identifies the Java package that it actually resides in, the 'plugins' package that is a member of my project, "Tom_Taggart_Tools".

Plugin addition using Python

The standard available tools in Whitebox's toolbox have one of two icons, a little wrench or a scroll. The tools with the wrench icon are written in Java and are compiled and the scrolled icon tools are actually scripts, some of which have been written in Groovy (higher performance) and some in Jython (Python for Java). You can write a script to call existing scripts, i.e. to automate a workflow, or you can write a script that will be seen by the Whitebox interface as a full-fledged plugin tool. That is, it will be listed in the toolbox and will available to be called by other scripts.

There's an example file containing code replete with comments focused on how to write this type of tool. If you open the Scripter, then open the file 'ExamplePluginScript.py' which is located in Whitebox_3_2_0/resources/plugins/Scripts then you should see that it is a well documented template for how to write a tool this way. The process, you should find, is far easier than the process of writing a Java tool for Whitebox. And there's none of the complications of having to compile a jar file and place the jar in the appropriate folder and then relaunch the program. All you need to do is write the tool in the Scripter, then any changes that you make to the script will be live. Once you've saved the script, the next time that you launch Whitebox, if it's been written correctly, you'll find that it's listed in the toolbox.

Note: At the top of the script, you will need these lines:

# the name variable is the unique identifier for this tool. It cannot contain any spaces.
name = "MyScript" 

# the descriptiveName variable is the name of the tool as it appears in the various tool listings. This name can contain spaces.
descriptiveName = "My Script"

# this string appears as a brief description in the status bar when the user clicks on your tool.
description = "This tool processes counts the number of records in a shapefile."

# these are the various toolboxes in the tool tree panel that this tool will appear in.
toolboxes = ["ConversionTools", "StatisticalTools"] 

This describes the basic process for plugin creation using python - it doesn't go into creating a dialog box, but this can be accomplished easily learning from existing files in the WhiteBox toolset as well.

Additionally, you can open any of the script plugin tools that are in the Scripts folder for good examples of how to do specific things, e.g. create a dynamic tool dialog that updates as the user enters data, or work with attribute tables or shapefiles, etc.

Now, if you're running your various tools thousands of times, the developer (WhiteBoxDev) suggests that you take a look at running them through the 'Run Plugin in Parallel' tool, which will allow you to run a tool many times in parallel, using all of the various cores that you have available. WhiteBoxDev says this can drastically cut down on the time of execution.

| improve this answer | |
  • Please note as well that you can use one of the three supported scripting languages (Python, JavaScript, and Groovy) to develop custom plugin tools directly within Whitebox GAT itself. This provides a far easier and more rapid pathway for integrating custom tools. The following tutorial describes this process: whiteboxgeospatial.wordpress.com/2014/10/15/… – WhiteboxDev Oct 15 '14 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.