Difference between revisions of "Scripting with BeanShell"

From OpenJUMP Wiki
Jump to navigation Jump to search
 
(One intermediate revision by one other user not shown)
Line 30: Line 30:
 
Some of the following scripts are not very useful. Instead they are indented as examples which can be easily adapted to perform useful tasks.
 
Some of the following scripts are not very useful. Instead they are indented as examples which can be easily adapted to perform useful tasks.
  
 +
* [[Beanshell:Changing linewidth of selected layers]]
 
* [[Beanshell:Saving View as Image]]
 
* [[Beanshell:Saving View as Image]]
 
* [[Beanshell:Loading an Image into the task]]
 
* [[Beanshell:Loading an Image into the task]]
Line 48: Line 49:
 
* [[Beanshell:Converting JML files to shapefiles]]
 
* [[Beanshell:Converting JML files to shapefiles]]
 
* [[Beanshell:Chain Copy/Paste/Move using PlugIns and CursorTool]]
 
* [[Beanshell:Chain Copy/Paste/Move using PlugIns and CursorTool]]
 +
* [[Beanshell:Create linestring from points with id attribute]]

Latest revision as of 08:11, 14 September 2016

What is BeanShell?

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

In the context of Jump, BeanShell enables the automation of repetative tasks or to accomplish tasks that are not possible using the GUI without the need for plugin modules or modification of the application source code.

See http://www.beanshell.org/ for more information on BeanShell.

BeanShell in OpenJUMP

To open the BeanShell scripting window select the following menu option:

View -> BeanShell...

It is a good idea to surround all your scripts in a set of braces. I.e.

{
  script...
}


In BeanShell you may access JavaBean properties as if they were fields. For example wc.layerManager is the same as wc.getLayerManager().

There is no facility to save and load a script. If you plan to reuse your scripts, develop the script in a text editor and then paste into the BeanShell window as needed.

If you want to write Beanshell scripts you can also use the Beanshell-Editor-JUMP Plugin (bsheditor4jump-0.2.jar) that has been written by Michael Michaud.

JUMP BeanShell examples

Some of the following scripts are not very useful. Instead they are indented as examples which can be easily adapted to perform useful tasks.