Attribute Error On Initial Window Opening

Hello,

I am having trouble with a script that I am writing. The purpose of the script is to move a button when alarms are selected in the Alarm Status Table. I was able to get the script to work appropriately, but I have to perform one “Action” in the runtime prior to it running correctly. That “Action” is selecting an alarm on the alarm status page. Once an alarm is selected it can be unselected and then whenever I return to the screen with the script the error will not reoccur until I reload the runtime, i.e. due to an update.

I am unsure why the script throws an error when I open the window if I have not yet performed the “Action” I described above, but works flawlessly after I perform this “Action”.

The script is a property change script on the Alarm Status Table. The content of the script is as follows.

component = event.source.parent.getComponent('Button')
rows = event.source.selectedAlarms.getRowCount()

if rows >=2:

   system.gui.transform(component, newX=259)

else:
   system.gui.transform(component, newX=210)

The error I am getting is as follows:

Traceback (most recent call last):
File "<event:propertyChange>", line 2, in <module>
AttributeError: 'NoneType' object has no attribute 'getRowCount'

at org.python.core.Py.AttributeError(Py.java:207)
at org.python.core.PyObject.noAttributeError(PyObject.java:1032)
at org.python.core.PyObject.__getattr__(PyObject.java:1027)
at org.python.pycode._pyx995.f$0(<event:propertyChange>:9)
at org.python.pycode._pyx995.call_function(<event:propertyChange>)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:782)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter$ActionRunner.run(ActionAdapter.java:312)
at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Ignition v8.0.14 (b2020062220)
Java: Azul Systems, Inc. 11.0.6

Any assistance in the matter would be greatly appreciated.

A judicious use of try/except

try:
   component = event.source.parent.getComponent('Button')
   rows = event.source.selectedAlarms.getRowCount()

   if rows >=2:
      system.gui.transform(component, newX=259)

   else:
	   system.gui.transform(component, newX=210)

except:
   pass
   #system.gui.errorBox('Something went wrong here.')
   # -or-
   #system.util.getLogger('myLogger')
   #myLogger.error('Something went wrong here.')

Normally, you should toss in some code as what to do when there is an exception. I’ll leave that part up to you.

Try add this at the top of your script:

if event.propertyName == 'selectedAlarms':
	# do your script

Based on the error it seems like your script is firing when the window opens before the component is initialized. By adding the above code, you will ensure to only run your script when the selectedAlarms property changes.

Thanks! Your suggestion worked perfectly!