Is there a trick to using the fpmi.dataset functions? I always get an error saying no such object exists.
Make sure you import the fpmi.dataset module before using the module’s methods, for example:
import fpmi.dataset
data = fpmi.dataset.toDataSet(queryResults)
or
from fpmi.dataset import toDataSet
data = toDataSet(queryResults)
I’m still getting same erro,
I’m population a drop down list using a query, then I want to add 1 addtional line to the beginning of the list.
I’m using this code with the action key pressed:
import fpmi.dataset
dropdown = event.source.parent.getComponent("Dropdown")
newRow = [5, "New Option"]
dropdown.data = fpmi.dataset.addRow(dropdown.data, 0, newRow)
and I’m getting error:
Traceback (innermost last):
File “event:keyPressed”, line 1, in ?
ImportError: No module named dataset
You should not need to import fpmi, as this is done for you for object scripts.
What version of FactoryPMI are you using? fpmi.dataset was only introduced in version 3.3.0 (Release Date 12/16/2008).
DB2,
You can’t add a row to a dataset directly. You have to use lists and the fpmi.dataset.toDataSet(#2) method. See this thread: http://www.inductiveautomation.com/forum/viewtopic.php?f=23&t=4737
You can add a row to an existing dataset - that’s what the fpmi.dataset.addRow function is for! I got his code working without a problem, and without having to import fpmi.dataset. I think DB2 may be running an older version of FactoryPMI before the fpmi.dataset module was added.
The IA guys must have added that in a version later than I have too. Thanks for the heads up. I’m pretty sure they changed the requirement to import the fpmi module in a more recent version too.
You have to import the fpmi module if you are writing a function, but otherwise it’s done for you.
e.g. in a button event scriptfpmi.gui.messageBox("Hello")
will work, but [code]def sayHello():
fpmi.gui.messageBox(“Hello”)
sayHello()
[/code]will give a namespace error on ‘fpmi’. To get this to work you would need [code]def sayHello():
import fpmi
fpmi.gui.messageBox(“Hello”)
sayHello()
[/code]Have a look at http://www.inductiveautomation.com/products/factorypmi/usermanual/source/technical/jython/events.htm for more information.
In some sense, you’re both right. Datasets are immutable - you technically cannot add a row to them directly. However, fpmi.dataset.addRow does exactly this, right? The trick is that fpmi.dataset.addRow function doesn’t actually alter the dataset that it is given: it returns a new dataset with the extra row.
As for DB2:
fpmi.dataset was added in FactoryPMI version 3.3.0 (Release Date 12/16/2008)
In your script: you should simply do an:
import fpmi
instead of
import fpmi.dataset