You can use any text editor to develop a scripting language. However, a standard text editor lacks of code assistant features. Most scripting languages are loose type. For example, to define a variable in JavaScript, you need to type:

var a;

 

It is difficult to determine what type of "a" later in the source code. With BeanShell, you can use a variable without declaring it, for example:

a = new File("file.txt");

 

Or you can declare it first:

File a = new File("file.txt");

 

Java IDE does not officially support code completion for scripting languages.  However, there is a workaround if you use BeanShell. First you need a Java IDE. If you do not have one, you can select NetBeans because it has the smallest file size. You can download the latest version of NetBeans at http://www.netbeans.org/downloads/index.html. The NetBeans Java SE package is enough. Second you need to set up a MagicDraw classpath.

 

To set up a classpath point in the MagicDraw library in NetBeans


  1. Click Tools > Libraries on the main menu. The Library Manager dialog will open.
  2. Click the New Library button. The New Library dialog will open.
  3. Specify a library name, for example, MD16.6. The Library type must be Class Libraries.
  4. Click OK to close the New Library dialog.
  5. Select your new library in the Libraries tree.
  6. Click the Add JAR/Folder button and add all the JAR files in <MagicDraw>/lib.
  7. Click OK to close the Library Manager dialog.

 

To develop a BeanShell script in NetBeans


  1. Click File > New Project on the main menu to create a Java application project. The New Project dialog will open.
  2. Select Java in the Categories box and Java Application in the Projects box, and then follow the instructions.
  3. Expand your project node in the Project window. The Libraries node will appear.
  4. Right-click the Libraries node and select Add Library from the shortcut menu.
  5. Select the MagicDraw library that you have previously created (see "To set up a classpath point in the MagicDraw library in NetBeans:") and click Add Library.
  6. Click File > New File on the main menu to add a new Java file.
  7. Select Java in the Categories box and Empty Java File in the File Types box, and then follow the instructions until finish.


You need to create a public static method in a Java file, for example, main() method, to follow the standard Java programming language. At the end of the file, insert a statement to call the static method. See the example in create_project_elements.bsh in the <MagicDraw>/samples/product features/macros directory.

The official filename extension for BeanShell is .bsh. However, you can add a .java file to the BeanShell scripting language.