Chapter 5: The Global Object

There are a few static functions in the Global scope that can be used to leave the scope of the current script execution to access other scopes in the workspace. However, since the script has no write permission to other projects, the access to outside scopes is limited.

getFinder()

{Function} - Returns new Finder instance for a given scope. A scope can be either a single object or a set of objects. Note: in case a single object is passed, the finder searches the whole containment tree of the given object. In contrast, passing a set (array) of objects will limit the finder to exactly the passed set of objects.

// use of second Finder instance
var parts = finder.findByType(Metamodel.sysml.SysMLPart);
if (!parts.isEmpty()) {
  // search only within the scope of the first part
  var secondFinder = Global.getFinder(parts.toList().get(0));
  secondFinder.find(...)
}

Stability 3 - Stable

getProjects()

{Function} - Returns a list of all project root objects found in the workspace.

var count = Global.getProjects().size();
console.log("There are {0} projects in the workspace", count);

Stability 3 - Stable

getTraces()

{Function} - Returns all traces within a project as a FindResult object. A single object has to be passed as parameter to determine the project scope. See the Finder and FindResult API for further use cases.

var count = Global.getTraces(finder.scope).size();
console.log("There are {0} traces in the project", count);

Stability 2 - Unstable

move()

{Function} - Moves a given element to a given container using a given containment relationship. If any of the parameters do not match, the function does nothing and returns false.

Returns true when successful.

var success = Global.move(requirement, newModel, "requirements");
console.log("The move was successful: {0}", success);

Stability 1 - Experimental