Context Scripts

Conext Scripts provide a way for AdvancedMiner users to extend the functionality of the system's GUI according to their own needs.

How do context scripts work?

The user defines the context based on his/her location within the system and various GUI actions (such as selecting a node or activating a component). Usually this context provides a list of scripts which can be executed. For example, for a model node the action Context Scripts is available. This action lets the user choose the script to be executed. The script collects the necessary data from the context and performs various operations on it, for example generates a report for the model.

In the case of open editors the Context Scripts action is available from the title bar's context menu.

Where can I find context scripts?

In the Services window there is the Contexts node, which groups all the available scripts. The contexts are divided into two groups: Nodes, which denote the nodes in the Metadata Repository and Editors, which denotes scripts for open components. More detailed contexts can be found deeper down in the hierarchy, for example for the Freq editor or PhysicalData nodes. The existing scripts can be edited and user created scripts can be added as well. Any saved changes are effective immediately and newly added scripts are instantly and automatically available in the given context.

Writing context scripts

The getContext() method is used to collect the context. This method returns an array of available contexts. For example, all selected nodes will be returned when more than one model node is selected. After gathering the context the user can use the capabilities of the Gython language and its integration with the environment to achieve the desired effects.

Example 14.32.  Printing the names of selected models when the script is saved in Contexts/Nodes/Mining Model.

from context import *
contexts = getContext()
for c in contexts:
   print c.name
                

What can be found in contexts:

  • the node representing the object from the metamodel (for example TestResult, MiningModel); in order to access the proper object it is necessary to use:

    context.object
                        

Other contexts use an API which is not yet publicly available.