How to call functions written in Python or Matlab directly in Mendix?

0
I’m a newbie of applicaiton development with Mendix. Acturally, I have writen a serious of calculationg functions and scripts by Python and Matlab to realize the core work of calculation. And I hope to use Mendix to organize all these functions, manage and export results, and provide a good-looking GUI, to make it more easily, efficientily and broadly used by my colleagues.   So, just as it’s put in the title, How to call functions written in Python or Matlab directly in Mendix?
asked
1 answers
5

you can try https://www.jython.org/download :

1- add the jar in userlib folder

2- make a java action to write python

 

 

example:

 

 

import javax.script.ScriptEngine;

import javax.script.ScriptEngineManager;

import javax.script.ScriptException;

 

public class Main {

 

     

    public static void main(String[] args) throws ScriptException {

        ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");

 

        

        engine.eval("import sys");

        engine.eval("print sys");

 

       

        engine.put("a", "42");

 

       

        engine.eval("print a");

        engine.eval("x = 2 + 2");

 

        

        Object x = engine.get("x");

        System.out.println("x: " + x);

    }

 

}

answered