Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Scripting in ICE using EASE"

(Using the Core and Client Services)
 
Line 15: Line 15:
  
 
== Using the Core and Client Services ==
 
== Using the Core and Client Services ==
 +
 +
Now that you have all of the tools necissary it is time to get started with scripting in ICE. Note that all of these tutorials will be in Python, but examples in both Python (Jython) and Javascript will be on GitHub at http://github.com/eclipse/ice in the examples/org.eclipse.ice.reflectivity.scripting folder. <br>
 +
 +
After firing up the script shell, the first thing to do is import an ease module that will allow us to control ICE (create items, edit their forms, etc.). A fresh shell should look something like the picture below:
 +
 +
[[File:scriptingNewShell.png]]
 +
 +
On the left is a handy list of variables, which you can click on to view all of the associated methods. This works especially well when accessing Java classes like we need to do to control ICE. <br>
 +
 +
=== Your first script ===
 +
 +
First, you need to import the module from ease 'System/Platform' with the command
 +
 +
<br><pre>loadModule('/System/Platform');</pre><br>
 +
 +
This enables the retrieval of OSGi Services that we will use. You can also load modeules with the 'Load an External Module' button in the shell's view. Now we simply need to get the core service of ICE to create, delete, and edit items.
 +
 +
<br><pre>coreService = getService(org.eclipse.ice.core.iCore.ICore);
 +
model = coreService.getItem(int(coreService.createItem("Reflectivity Model")));
 +
coreService.processItem(reflectMOdel.getId(), "Calculate Reflectivity", 1);</pre><br>
 +
 +
The first command,
 +
 +
<br><pre>coreService = getService(org.eclipse.ice.core.iCore.ICore);</pre>
 +
gets the service from the core of ice to process items. The second command then creates a new item with
 +
the core.createItem("item name") command and then gets its reference. I use the int() command to change the returned type of string into a integer for the core.getItem() command. And finally, the
 +
 +
<br><pre>coreService.processItem(reflectModel.getId(), "Calculate Reflectivity", 1);</pre><br>
 +
 +
will process the item from the core. This takes the item id to identify which item to process, the action name for processing (as there can be many different ways to process the same item), and the client id which is usually one. Run these commands and you have just created a new item and processed it all without the touch of a button!

Latest revision as of 09:43, 9 July 2015

Introduction

Scripting ability from the console is now availiable in ICE thanks to Eclipse EASE integration. EASE makes it possible to encapsulate the core services in ice and use them through Javascript and Jython commands. EASE comes with several pre-loaded modules to allow for accessing the services, file IO, simple graphing, and more. We will focus on using the Platform module to access the core services in ICE.

Getting Setup

To open the shell (if you want to use scripting dynamically in ICE), go to Window in the top toolbar, select Show View -> Other...
A window will appear to select the specific view we need. Scroll down until you see a folder called Scripting. Inside that select Script Shell and click OK (it should look like the picture below). The new view will appear at the bottom of your screen.

A picture showing the script shell selection view described above
The script shell view to select


If you want to use Python integration via Jython, then the next step is to install the Jython tools for EASE. Go to Help in the top toolbar and select Install EASE Components. A window will open displaying the available components to install. Check the box next to EASE Jython Integration and then select Finish. The Jython interpreter and shell will be installed into ICE.

A picture showing the installer for the EASE Jython tools
Jython EASE Integration

Using the Core and Client Services

Now that you have all of the tools necissary it is time to get started with scripting in ICE. Note that all of these tutorials will be in Python, but examples in both Python (Jython) and Javascript will be on GitHub at http://github.com/eclipse/ice in the examples/org.eclipse.ice.reflectivity.scripting folder.

After firing up the script shell, the first thing to do is import an ease module that will allow us to control ICE (create items, edit their forms, etc.). A fresh shell should look something like the picture below:

ScriptingNewShell.png

On the left is a handy list of variables, which you can click on to view all of the associated methods. This works especially well when accessing Java classes like we need to do to control ICE.

Your first script

First, you need to import the module from ease 'System/Platform' with the command


loadModule('/System/Platform');

This enables the retrieval of OSGi Services that we will use. You can also load modeules with the 'Load an External Module' button in the shell's view. Now we simply need to get the core service of ICE to create, delete, and edit items.


coreService = getService(org.eclipse.ice.core.iCore.ICore);
model = coreService.getItem(int(coreService.createItem("Reflectivity Model")));
coreService.processItem(reflectMOdel.getId(), "Calculate Reflectivity", 1);

The first command,


coreService = getService(org.eclipse.ice.core.iCore.ICore);

gets the service from the core of ice to process items. The second command then creates a new item with the core.createItem("item name") command and then gets its reference. I use the int() command to change the returned type of string into a integer for the core.getItem() command. And finally, the


coreService.processItem(reflectModel.getId(), "Calculate Reflectivity", 1);

will process the item from the core. This takes the item id to identify which item to process, the action name for processing (as there can be many different ways to process the same item), and the client id which is usually one. Run these commands and you have just created a new item and processed it all without the touch of a button!

Back to the top