Event Scripts (Gateway) imported function undefined

–Ignition 7.5.3 (b1163)/Win2k8 Server Enterprise on VMWare ESXi 5.0–

I know I must be missing something absurdly simple and would greatly appreciate any help from the forum!

I set up the following event script (gateway) to fire on appropriate tag changes:

import string
from app import CIP_Log  #<-- also tried "import CIP_Log" and "import app"

strWho = event.tagPath.itemName

if string.find(strWho, "CIP2") >= 0: CIP_Start("CIP2")
elif string.find(strWho, "CIP3") >= 0: CIP_Start("CIP3")
elif string.find(strWho, "CIP4") >= 0: CIP_Start("CIP4")
elif string.find(strWho, "CIP5") >= 0: CIP_Start("CIP5")
elif string.find(strWho, "CIP6") >= 0: CIP_Start("CIP6")
elif string.find(strWho, "LACTA") >= 0: CIP_Start("LACTA")

which generates the following error:

Traceback (most recent call last):
  File "<TagChangeScript:UD_Datalogs/All_CIP_Start>", line 8, in <module>
NameError: name 'CIP_Start' is not defined

	at org.python.core.PyException.fillInStackTrace(PyException.java:70)
	at java.lang.Throwable.<init>(Throwable.java:181)
	at java.lang.Exception.<init>(Unknown Source)
	at java.lang.RuntimeException.<init>(Unknown Source)
	at org.python.core.PyException.<init>(PyException.java:46)
	at org.python.core.PyException.<init>(PyException.java:43)
	at org.python.core.PyException.<init>(PyException.java:61)
	at org.python.core.Py.NameError(Py.java:246)
	at org.python.core.PyFrame.getname(PyFrame.java:257)
	at org.python.pycode._pyx43.f$0(<TagChangeScript:UD_Datalogs/All_CIP_Start>:13)
	at org.python.pycode._pyx43.call_function(<TagChangeScript:UD_Datalogs/All_CIP_Start>)
	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:1261)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:539)
	at com.inductiveautomation.ignition.common.script.TagChangeScriptManager$TagChangeScriptHandler$Runner.run(TagChangeScriptManager.java:219)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

In the Script Module Editor, I have one package, the default “app”, containing two scripts “CIP_Log” and “Lookups”. The first few lines of CIP_Log are:

def CIP_Start(strCIP_Unit):
	import system
	import datetime
	import app.Lookups
# --more code below--

… what am I missing? It shouldn’t be a scope issue…

What about trying something more like this (shouldn’t have to import app):

import string

strWho = event.tagPath.itemName

if string.find(strWho, "CIP2") >= 0: app.CIP_Start("CIP2")
elif string.find(strWho, "CIP3") >= 0: app.CIP_Start("CIP3")
elif string.find(strWho, "CIP4") >= 0: app.CIP_Start("CIP4")
elif string.find(strWho, "CIP5") >= 0: app.CIP_Start("CIP5")
elif string.find(strWho, "CIP6") >= 0: app.CIP_Start("CIP6")
elif string.find(strWho, "LACTA") >= 0: app.CIP_Start("LACTA")

I’m guessing by the way you’re importing that you’re trying to save yourself from having to write “app” over and over - so try this:

[code]import string
from app import CIP_Log

strWho = event.tagPath.itemName

if string.find(strWho, “CIP2”) >= 0: CIP_Log.CIP_Start(“CIP2”)

more code[/code]

Yeah, you still have to reference CIP_Log each time, but at least it saves you from writing “app” for each function call. :wink: