Python and C++ calls

0
Hi all, Is it possible to use Python code and C++ code like β€œJava Action call” from the toolbox? Will it be available?
asked
4 answers
1

No, you can't extend your app with C++ or Python the same way as with Java. You could try to run Python or C++ code from Java (using e.g. Jython or JNI respectively), but it's more complicated and you will probably run into unexpected issues.

 

Although I am not involved in the roadmap of Mendix, looking at their priorities over the past few years, I don't believe they will implement C++ or Python support: the choice has been made to support Java as general purpose programming language, so there seems to be little need to add a second language.

answered
6

Yeah! Jython supports reflection (quick prototype):

    try{
        var PythonInterpreter=Java.type("org.python.util.PythonInterpreter");
        var PySystemState=Java.type("org.python.core.PySystemState");
        var Properties=Java.type("java.util.Properties")
        var System=Java.type("java.lang.System")
        var pre_props = System.getProperties();
        var props = new Properties(); 
        home=PythonInterpreter.class.getProtectionDomain().getCodeSource().getLocation().toString()
        props.setProperty("python.home",home);
        props.setProperty(PySystemState.PYTHON_CACHEDIR_SKIP, true);
        props.setProperty("python.import.site", false);
        props.setProperty("python.path", "/tmp/always");
        props.setProperty("python.verbose", "debug");
        PythonInterpreter.initialize(pre_props, props,[]);
        var pyInterp = new PythonInterpreter();
        pyInterp.set("ctx",root.getContext());
        pyInterp.set("INFO",com.mendix.systemwideinterfaces.core.IFeedback.MessageType.INFO);
        pyInterp.exec(
            "import com.mendix.webui.FeedbackHelper.addTextMessageFeedback\n"+
            "com.mendix.webui.FeedbackHelper.addTextMessageFeedback(ctx,INFO,'Hello Python',True)"
        )
    }catch(e){
        alert(e)
    }

You only need jython-2.7.0.jar, works on cloud

answered
1

Hello Anton. This article might be useful: https://ubiops.com/building-a-low-code-app-powered-by-ai/

It shows how to serve a Python (or R) model and integrate it in a Mendix app.

answered
0

No, your best option is to communicate with your C++ or Python (or any other language for that matter) via interfaces.

answered