Math Functions



For the sake of completeness, here are the Python modules that you can use in FactoryPMI:



Also, I just want to re-iterate that the expression language and the scripting language are completely and utterly separate. Don’t look at functions under the expression language docs and think that they will translate over to action scripts.



Here is a reference of Python modules. The list doesn’t exactly match up with the FactoryPMI Jython modules. The functions will be the same for the common modules.



Ok, this is probably a dumb question, but that never stopped me before. Is there a way to get python modules to work in FPMI if they are not in the list above? I’ve found some nice modules that I have been playing around with, but can’t seem to import them.



Yes and No.

You’d have to copy-and-paste them as app.* modules. Its tricky, though, because the scoping rules are a bit different, so you may have to mess with imports. Also, you’ll have to resolve any dependencies that that module uses. It can be done, but its a pain. Are there standard libraries that are missing that you’d like to see?



No standard libraries, but I’ve been experimenting with, and found a few things that I could use. I’m trying to add graphical features that go a little beyond what I can do with images. Being able to programatically create graphics is more to my liking.



Ah, that might be a bit tricky to integrate. I know this is a bit of a tease, but you’re going to like our native 2D drawing feature, which should lend itself to programatically-created graphics very well. Its still a ways off, though, sorry.



Ok, what if I came up with a .py script that does what I need- can I call it with the fpmi.system functions? I tried various flavors of fpmi.system.execute([“python”, “”]), but didn’t get anything to work.

What I’m trying to do is dynamically draw what the machine just produced. I have the exact data points, it it should be pretty easy to display the exact dimensions and out-of-tolerance points. I could do it with a graph, but a drawing would be awesome.



No, you wouldn’t execute it like that, that would have the python on the client machine run that script (actually, maybe that is what you want? I’m not sure…)

I think you want to import it into your project’s global script modules, but I don’t see where it is going to draw this thing…

Now, I might be opening a can of worms with this, but take a look at this window (You’ll need to be running the 3.2.0 beta. And, you’d probably want to put the button code in a timer to continually draw, as normal repaints will clobber your drawing…)

This example uses Java2D. See the Java API for a reference, or Google for tutorials.
drawcanvas.fwin (14 KB)



Now that I think about it, we should totally have a “PaintableComponent” component, where you provide its painting code in Jython using Java2D. All you’d need is a hook into the repaint event.

I think we might just have to sneak this into the 3.2.0 release…

Thanks for the idea!



Bring it on. I’ve slogged through Siemens stuff for 20 years, and if I can handle German software, I can handle anything.

I actually gave that some thought. I realize that some features might just be too intense for a low end client PC, so I would have no problem popping up a message telling the tech to go to a different PC to get to the advanced graphics if the python libraries weren’t installed on the local PC. That’s definitely an option I could live with.

[quote=“Carl.Gould”]I think you want to import it into your project’s global script modules, but I don’t see where it is going to draw this thing…
That’s why I was wondering if I should just launch a stand-alone Python script from fpmi. I could pass in the data points as parameters or keep them in a file or something. I’m just brainstorming for now, but don’t mind putting in the effort if it has a prayer of working.



Yeah, if you wanted to launch the python script externally on the client machine, you could do that just fine. You could even write the script or an input file for the script dynamically through FPMI with the fpmi.file module.

The tricky part is making sure Python is installed on your client machines.



I just installed the beta version, and now I get a message when I launch a project. Any ideas?

java.lang.NoClassDefFoundError: com/calmetrics/factoryhmi/application/gateway/DataSet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at Source)
at Source)
at$000(Unknown Source)
at$ Source)
at Method)
at Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at com.inductiveautomation.factorypmi.plugins.reporting.ReportingDesignerHook.(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.inductiveautomation.factorypmi.designer.model.DesignerPluginManager.loadPlugins(
at com.inductiveautomation.factorypmi.designer.FPMIDesigner$
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at Source)
Caused by: java.lang.ClassNotFoundException: com.calmetrics.factoryhmi.application.gateway.DataSet
at$ Source)
at Method)
at Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
… 29 more



You didn’t upgrade the reporting plugin at the same time. Make sure when you run the beta installer to choose custom, and check the reporting plugin.



Got it, thanks.

I just took a look at the window: Awesome! I’ve got an immediate application where I am using a lot of lines on my GUI to indicate product paths, and until now I have been using a painful method of creating images of lines. Each time I needed a different color, thickness, or type of line I had to start over. But this gives me the possibility of generating any kind of line type, from a simple line to complex line types (such as railroad tracks) dynamically. I’ll get this working, and then it’s on to 3d…



Ok, I’ve been experimenting with this stuff with pretty good results. But I am having a problem understanding when windows refresh/update on their own.

For instance, I took your sample code and changed it so that I draw only lines on the screen (no polygon or fills), so it has a transparent effect. Basically, I’m just drawing lines on top of my existing screens. For my testing, I stuck the code on a button, and on the click event I read the coordinates from the label and create the lines. I erase the previous line with “canvas.update(g)” just before drawing the line. This works fine.

But, what I want to do is execute the same code when the screen opens or when someone returns to this screen after tabbing to another screen (my line disappears when the screen refreshes for any reason, which I would expect). But when I add the code to the window getfocus or internalframeopened/activated events, at the most I see the line flicker for a moment. So, it looks like the screen refreshes on its own after it opens or gets focus. Do I have access to this event/action somehow?



Yeah, I thought you’d have problems like that, which is why I suggested putting the paint code on a timer. We did go ahead and implement a pantable canvas component for 3.2.0 which has much, much better support for all this, so you won’t have to worry about such details.



That’s great. I really don’t like using timers, and would prefer to do the screen updates programatically, which works most of the time. I’ll check out 3.2.0 when it’s out.



Okay, ask and you shall receive! FactoryPMI 3.2 contains the Paintable Canvas component. Users familiar with scripting should quickly grasp the depth of the power that this component delivers. Time to brush up on your Java2D. (See the example script in the Paintable Canvas for some inspiration)



I’m pretty late to this discussion, and the new paintable canvas in 3.2 may solve all your problems, but… we’ve done a lot with flash (not within pmi, though) to create custom drawings on the fly. We use it mostly to dynamically generate control charts.