Using 3rd-party java python libraries

Hi all, I would like to ask how do I add and use 3rd-party java python libraries in Ignition in the scripting window.

I would like to use Datamelt because of the array feature it has similar to Numpy using jnumeric

Code in Python but in C so I need to convert it into something Jython can recognize:

import numpy #array and math functions
import time #for time delay, depends on how fast we want to refresh the image

### intialising variables for the data processing algorithm, need to add this to SCADA code.
history = numpy.full((32, 32,5), numpy.nan)
idx = 0
movavgmax = numpy.full((5,1), numpy.nan)
movavgmin = numpy.full((5,1), numpy.nan)
hyst = 0.8;
    ###start of data processing algorith
    ### compute moving average from last 5 images
    array = rawdata
    idx = idx + 1
    history[:,:,(idx-1)%5] = array
    movavgarray = numpy.nanmean(history,axis=2)

The simplest deployment is to stick the jars in your Ignition gateway’s ../lib/core/common and restart. Then those jars will be available for import like any other java library in jython (no wildcards).

A more professional and reliable method would be to deploy the jars in a .modl file with simple module hooks to register scripting functions.

So the first way is like putting the library into a file location that Ignition can find and it will be as simple as this for the importing like importing libraries in python ?
Running this Example on a Scripting Console in ignition after putting the jar file into the gateway’s directory

import jnumeric.JNumeric as np
a = np.array(10)
b = np.array( [[1,0],[0,1]],'f') # assume float
print b

The second way would be like this:

How to use Maven & Using Maven-plugin with Ignition SDK to make a .modl file

I’m a bit short of time for my project… so I might go with the first way for now in this case. But is there any issues using the first way that I should be aware of ?

Your imports will have to use DMelt’s java class names, not the python names. But otherwise, yes, it’s that simple.

Something like this example ? Java Class importing in Jython

I never used or learn java , so it’s a bit new to me.

1 Like

I tried inserting the jar file into the directory as shown in the picture below:

Then using the Script Console to run it, receives an error that the module is not found :

Link to download dmelt-2.7 file

Did you restart your gateway and then restart your designer?

I doubt jnumeric’s java package name is “jnumeric”. Open the jar and look at the heirarchy of folders. According to github, it should be “com.github.tbekolay.jnumeric”.

1 Like

I did and even restarted my computer

Using 7-Zip to open the .jar file

If you want to use JNumeric you’ll also need to install the Python lib:
This would go into /user-lib/pylib/ in the installation directory.

The sourceforge repo has a discussion from 2009 where somebody reports it doesn’t work with Jython 2.2…

We just updated to Jython 2.2, and found that JNumeric is incompatible. It appears most (if not all) the issues are in the PyMultiarray, and are related to signature changce in the jython.jar file. Help…?

This is one of the most dead and abandoned looking projects I’ve ever seen. I doubt this will work.


Thank you, I manage to run the example from Dmelt using GitHub - tbekolay/jnumeric: NumPy-like syntax for Jython JNumeric File

I placed the files in both the Ignition gateway’s ../lib/core/common and the /user-lib/pylib/ mentioned by PGriffith and the Script Console recognizes the functions

just restarting the Ignition gateway and the designer (if required in clients) is enough.