Scripting Module - Some Question

I’m currently trying to write a simple module. Here some questions.
Hope IA team and Java Pros have patience.

  • I’ve been following the scripting-rpc example and is a easy to follow. My biggest question now is where to write code that would be equivalent to main method?

  • In the example, it implements an interface that lives in common scope. Are interfaces mandatory to implement the AbstractScriptModule class?

  • The example computes the final calculations in the Gateway Scope under the Gateway Script Module. This means the module is letting the gateway doing the hard work. Can I use a condition to let the other scopes to do the hard work when possible? If so, how the project structure should change?

JDK 1.8 - Maven - Ignition 7

Any scripting function you implement that doesn’t need to communicate across scopes doesn’t need RPC interfaces at all. The purpose of an interface in common (and dependent implementations) is to make it easy to expose scripting functions that expose gateway resources in any scope.

If you don’t need RPC, just create classes with the functions you wish to expose and register them in your hooks. Generic functions can be static public and the class itself registered. You can break up your implementations into multiple registrations, too, even for the same namespace.

If you do need RPC from Vision Client and/or Designer, keep in mind that RPC is a generic resource for your module, not necessarily just for scripting. The common interface you use for RPC has to cover all of your module’s communication needs. RPC lookup gives your gateway hook the opportunity to deliver an implementation instance that carries project/user customization. You may not need that, and your RPC class(es) would be much simpler.

1 Like

Brilliant, let me process that wisdom and I’ll return for more haha.

If I could have more example would be cool, do you know any open resource to explore?.
In my mind: The gold mine I wish to have access under aggregates from the Simulation Aids haha :star_struck:

Let me offer something simpler:

public class Datasets {

	protected static final Pattern munger = Pattern.compile("\\W+");
	public static String mungeColumnName(@ScriptArg("columnname") String columnName) {
		String munged = munger.matcher(columnName).replaceAll("_");
		if (Character.isDigit(munged.charAt(0)))
			return "_"+munged;
		return munged;

	public static final Class<?> TransientDataset = TransientDataset.class;

This shows a dead-simple class containing only statics to expose. One is a function, the other is a class. (The latter’s constructors and static fields are trivial to use in jython having that one-line.)

The above is added to a script manager with this:

		manager.addScriptModule("system.dataset", Datasets.class, new MetaDocProvider("Datasets"));

(My MetaDocProvider just looks up functions and arguments in the shared localization bundle.)

Pssst! Simulation Aids is free…


And that is awesome, I mean to give it a look to the source code haha.

Thanks @pturmel your example helped my a lot.