07:58:48.068 [designer-script-shared-timer-[Melt_Dashboard]] ERROR com.inductiveautomation.ignition.common.script.TimerScriptTask - Error executing global timer script: Melt_Dashboard/windowRotate @30,000ms . Repeat errors of this type will be logged as ‘debug’ messages.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
File “<TimerScript:Melt_Dashboard/windowRotate @30,000ms >”, line 3, in
KeyError
at org.python.core.Py.KeyError(Py.java:225)
at org.python.core.PyObject.__getitem__(PyObject.java:655)
at org.python.pycode._pyx26.f$0(<TimerScript:Melt_Dashboard/windowRotate @30,000ms >:4)
at org.python.pycode._pyx26.call_function(<TimerScript:Melt_Dashboard/windowRotate @30,000ms >)
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.ignition.common.script.ScriptManager.runCode(ScriptManager.java:601)
at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:88)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: org.python.core.PyException: Traceback (most recent call last):
File “<TimerScript:Melt_Dashboard/windowRotate @30,000ms >”, line 3, in
KeyError
That means the result from system.nav.getCurrentWindow() wasn’t one of the windows in your dictionary (as a key). You have to handle that case. Either test with if win in swapWindows: or use a try-except block to catch the exception.
I tried the if win example not for sure on the try-except one. I get a error with the if win example.
if win in swapWindows:
swapWindows = {"Melt Overview":"Test","Test 2":"Test 3","Test 3":"Test 5"}
win = system.nav.getCurrentWindow()
nextWindow = swapWindows[win]
system.nav.swapTo(nextWindow)
09:28:02.592 [designer-script-shared-timer-[Melt_Dashboard]] ERROR com.inductiveautomation.ignition.common.script.TimerScriptTask - Error executing global timer script: Melt_Dashboard/windowRotate @30,000ms . Repeat errors of this type will be logged as 'debug' messages.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
File "<TimerScript:Melt_Dashboard/windowRotate @30,000ms >", line 1, in
NameError: name 'win' 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._pyx73.f$0(<TimerScript:Melt_Dashboard/windowRotate @30,000ms >:5)
at org.python.pycode._pyx73.call_function(<TimerScript:Melt_Dashboard/windowRotate @30,000ms >)
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.ignition.common.script.ScriptManager.runCode(ScriptManager.java:601)
at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:88)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: org.python.core.PyException: Traceback (most recent call last):
File "<TimerScript:Melt_Dashboard/windowRotate @30,000ms >", line 1, in
NameError: name 'win' is not defined
Probably because your dictionary doesn’t include some of the windows you’re swapping to, as keys. For example the first key in your dict has a value of “test”. There is no key called “test” and so when the script changes the window to this and the script runs again, it’s not going to find it in the dictionary and will therefore not result in any more window changes. Your issue is semantic
Consider using a list of window names instead of a dictionary. Use the .index() method of the list to find the current window, then use (idx+1) % len(thelist) to pick the next window. Then there’s no need to explictly make keys and values for every transition.
Note that you can put a list (or dictionary, for that matter) on separate lines to make it easier to read, and make sure the order of items is… um… in order.