I’m try to read value from different column in a row of my powertable.
I have associated script to onclick event for power table, but every time i have a error.
Here my code:
ptable = event.source.getComponent()
selRow = ptable.selectedRow
if selRow > -1:
idFer = ptable.data.getValueAt(selRow, "ID")
print idFer
system.tag.write("[Client]testtag",idFer)
somebody can explain me why?
Thanks
What is the error? I’m guessing it has something to do with getComponent(), which expects an argument. If this script is on the power table then simply using event.source will give you the power table object, no need to use getComponent. If you’re using an extension function then use ‘self.data’ to get the power table’s dataset.
Also, in the future you can add triple back quotes before and after your code blocks to format it nicely for the forum.
Here error logged in console :
``
10:40:45.973 [AWT-EventQueue-0] ERROR Vision.Components.AdvancedTable - Error invoking extension method.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
File “”, line 19, in
NameError: name ‘event’ is not defined
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getname(PyFrame.java:257)
at org.python.pycode._pyx3.f$0(<extension-method onMousePress>:23)
at org.python.pycode._pyx3.call_function(<extension-method onMousePress>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:634)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:138)
at com.inductiveautomation.factorypmi.application.components.VisionAdvancedTable$7.onPress(VisionAdvancedTable.java:380)
at com.inductiveautomation.ignition.client.util.gui.CommonMouseAdapter.mousePressed(CommonMouseAdapter.java:55)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at com.jidesoft.docking.b.a(Unknown Source)
at com.jidesoft.docking.DefaultDockingManager.handleEvent(Unknown Source)
at com.jidesoft.docking.DefaultDockingManager$55.eventDispatched(Unknown Source)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Unknown Source)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source)
at java.awt.Toolkit.notifyAWTEventListeners(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(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 java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.python.core.PyException: Traceback (most recent call last):
File “”, line 19, in
NameError: name ‘event’ is not defined
Thanks for your help
Extension methods aren’t events. They have no event object. Where you would use event.source
in an event method, you must use self
in an extension method. Also look at the the extension function signature (in the def line) for the other parameters supplied to the function.
1 Like