# Event Scripts (Gateway) imported function undefined

**URL:** <https://forum.inductiveautomation.com/t/event-scripts-gateway-imported-function-undefined/5358>\
**Category:** Ignition\
**Created:** [October 30, 2012, 6:13pm UTC](https://forum.inductiveautomation.com/t/event-scripts-gateway-imported-function-undefined/5358 "2012-10-30T18:13:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmoon](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dmoon](https://forum.inductiveautomation.com/u/dmoon)\
**Post date:** [October 30, 2012, 6:13pm UTC](https://forum.inductiveautomation.com/t/event-scripts-gateway-imported-function-undefined/5358/1 "2012-10-30T18:13:27Z")

</div>

–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:

```auto
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:

```auto
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:

```auto
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…

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 30, 2012, 6:28pm UTC](https://forum.inductiveautomation.com/t/event-scripts-gateway-imported-function-undefined/5358/2 "2012-10-30T18:28:54Z")

</div>

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

```auto
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")

```

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [October 30, 2012, 6:56pm UTC](https://forum.inductiveautomation.com/t/event-scripts-gateway-imported-function-undefined/5358/3 "2012-10-30T18:56:58Z")

</div>

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. 😉
