Jython import external file

I am new to this platform and have gotten one of the example modules to build and run. I would like to write a .py Jython file and be able to call functions from it within my module. I can run Jython from within Ignition and the script gui tool. But I want to have my code in a file that I can compile with my module so it is self contained, and the end user doesn't have to do extra configurations.

I tried including the .py file as a resource in my build pom, which didn't include in my .modl but rather in the .jar inside the .modl and when i try to call the script it can't be found, so I'm obviously doing it wrong. I read the documentation but can't see info about external files. I've been battling this issue for a few weeks now and I'm out of ideas on how to get this to work.

Is there an example of how to include a .py file into a module so I can call functions from it?

Thanks

You should be using the script library for this. That's what it's for.

If your external script uses python 3 syntax or C libraries, you should rewrite it to be jython-compatible, and put it in the library.

The whole point of Jython is that you can write the code as Java classes and call them from python inside Ignition. Write your classes as Java, include them in your module and then you can import the classes in python scripts in any script part of Ignition.

1 Like

There's no simple way to do this in Ignition with the SDK. And completely breaks all of the advantages of building a module in the SDK. You should just place your jython in the root inheritable project in your systems.

1 Like