Let’s use the script editor – Part 1 –

Hello, this is Lily.

Are you using a Script Editor?
I want you to use it, this plug-in is pre-installed if you are using Astah Professional version 7.2 or later. If you are using a product that is not included, install it – How to Install.
Let’s use it! It is not difficult.


Easy to use

Displays a character string.
Please display the script editor, write print("Hello World!") in the editor part, and press the execute button. Using the print method will display the string in the execution result.

image10

You can also use it by extracting the part of the character string as a variable.

image11

Functions can also be used. The third line to the sixth line are printMessage functions.

image12

You can also pass arguments to functions.

image13

An array can also be used.
You can also export the contents of arrays freely by using if statement or for statement.

image5

In this way you can write and execute in JavaScript in the Script Editor. The way of writing above is an example, so there may be better ways of writing.


Try using Java classes

Since we want to get the path of user home we will use the System class.
Passing user.home key to getProperty(String key) will get the user home path (other keys are also described in getProperties() in detail).

If you write Java.type('java.lang.System') you can use the System class.

image6


Try using Astah API

Astah has Astah API for manipulating it. You can do various things such as rewriting the contents of the project without running the product, exporting the contents of the model in the project. There are many APIs that can be used in the script editor as well.

Try using the predefined variable “astah”

In the Script Editor, ProjectAccessor of Astah API is defined as variable astah. Try using the predefined variable “astah”.

You can obtain the version of the product with the getAstahVersion().

image7

There are many other operations in ProjectAccessor, so you can get various information.

image8

Use undefined class

Classes that are not defined can be used in the way of Try using Java classes.

※ From here it will only be executable if the edition is professional / community, but please change as appropriate

Create a new project and create several classes.

image9

You search all classes in the project using findElements(Class elementKind) of the defined variable astah (ProjectAccessor). In order to use this method you have to pass elementKind as an argument. The model of the class is IClass (but as you can see from this page IClass includes interfaces etc).


Try running the sample program

For those who want to do something more advanced, please research and run Use scripting language to access models in Astah.
I think you can understand what kind of things can be done.


I think that I would like to write another article when next month.
Let’s do some more difficult things. Well then!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s