# Updating Template Canvas dataset to "draw" dots

**URL:** <https://forum.inductiveautomation.com/t/updating-template-canvas-dataset-to-draw-dots/19672>\
**Category:** Ignition\
**Tags:** python, ignition79, scripting\
**Created:** [September 14, 2018, 10:36am UTC](https://forum.inductiveautomation.com/t/updating-template-canvas-dataset-to-draw-dots/19672 "2018-09-14T10:36:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agn](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@agn](https://forum.inductiveautomation.com/u/agn)\
**Post date:** [September 14, 2018, 10:36am UTC](https://forum.inductiveautomation.com/t/updating-template-canvas-dataset-to-draw-dots/19672/1 "2018-09-14T10:36:08Z")

</div>

Hi.

I’m currently testing out drawing “Dots”(template) within a Template Canvas.  
These “Dots” would act as an overlay over an svg-drawing to represent alarms. Each tag got 2 Associated Properties( xPos, yPos), which are extracted from the alarmStatus() object.  
The script is working and the drawing of the dots do happen, but I recieve a few exceptions every time the script is called.  
Anyone able to understand what is going on?

Edit: I’m currently manipulating the dataset of the Canvas Template.

As seen in the script, no event is either parsed to the method nor referenced in the script.

```auto
 NameError: global name 'event' is not defined 
```

[details=Script][code]  
def GetActiveUnackedCoordinates():  
import system  
import re  
alarmList = system.alarm.queryStatus(state=[“ActiveUnacked”])

```
aProp0 = "name"
aProp1 = "xPos"
aProp2 = "yPos"

h1 = "name"
h2 = "template"
h3 = "x"
h4 = "y"
h5 = "width"
h6 = "height"
h7 = "z"

h2Value = 'Dot'
h5Value = '10'
h6Value = '10'
h7Value = '0'

headers = [h1, h2, h3, h4, h5, h6, h7]
aProps = [aProp0, aProp1, aProp2]
dataList = []
data = []

k = 0
j = 0
while k < len(alarmList):
	#Convert to string
	alarmToSearch = str(alarmList[k])
	while j < len(aProps):
	
		search = r'\b\w*' + aProps[j] + r'=(\w*\b)'
		r = re.compile(search)
		temporary = (''.join(r.findall(alarmToSearch)))
		dataList.insert(j,temporary)
		j += 1
	
	data.append([dataList[0], h2Value, dataList[1], dataList[2], h5Value, h6Value, h7Value])

	k += 1
	j = 0
try:
	return system.dataset.toDataSet(headers, data)
except ValueError:
	 system.gui.warningBox("Something isn't right")
#table = event.source.parent.getComponent("MainSiteCanvas")

#table.data = ds
#return table

```

[/code][/details]

[details=Expression]`
toDataSet(
	runScript ("project.AlarmFunctions.GetActiveUnackedCoordinates()", 10000)
)
`[/details]

[details=Exception][code]  
12:30:33.409 [AWT-EventQueue-2] ERROR Vision.TemplateCanvas - Error invoking extension method.  
org.python.core.PyException: Traceback (most recent call last):  
File “”, line 14, in initializeTemplate  
NameError: global name ‘event’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getglobal(PyFrame.java:265)
at org.python.pycode._pyx3.initializeTemplate$1(<extension-method initializeTemplate>:17)
at org.python.pycode._pyx3.call_function(<extension-method initializeTemplate>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:376)
at org.python.core.PyFunction. __call__ (PyFunction.java:371)
at org.python.core.PyFunction. __call__ (PyFunction.java:361)
at org.python.core.PyFunction. __call__ (PyFunction.java:356)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:154)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._finishBuilding(TemplateCanvas.java:375)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$TemplateLoader.done(TemplateCanvas.java:314)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.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)

```

12:30:33.414 [AWT-EventQueue-2] ERROR Vision.TemplateCanvas - Error invoking extension method.  
org.python.core.PyException: Traceback (most recent call last):  
File “”, line 14, in initializeTemplate  
NameError: global name ‘event’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getglobal(PyFrame.java:265)
at org.python.pycode._pyx3.initializeTemplate$1(<extension-method initializeTemplate>:17)
at org.python.pycode._pyx3.call_function(<extension-method initializeTemplate>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:376)
at org.python.core.PyFunction. __call__ (PyFunction.java:371)
at org.python.core.PyFunction. __call__ (PyFunction.java:361)
at org.python.core.PyFunction. __call__ (PyFunction.java:356)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:154)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._finishBuilding(TemplateCanvas.java:375)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$TemplateLoader.done(TemplateCanvas.java:314)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.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)

```

12:30:33.418 [AWT-EventQueue-2] ERROR Vision.TemplateCanvas - Error invoking extension method.  
org.python.core.PyException: Traceback (most recent call last):  
File “”, line 14, in initializeTemplate  
NameError: global name ‘event’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getglobal(PyFrame.java:265)
at org.python.pycode._pyx3.initializeTemplate$1(<extension-method initializeTemplate>:17)
at org.python.pycode._pyx3.call_function(<extension-method initializeTemplate>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:376)
at org.python.core.PyFunction. __call__ (PyFunction.java:371)
at org.python.core.PyFunction. __call__ (PyFunction.java:361)
at org.python.core.PyFunction. __call__ (PyFunction.java:356)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:154)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._finishBuilding(TemplateCanvas.java:375)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$TemplateLoader.done(TemplateCanvas.java:314)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.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)

```

12:30:33.422 [AWT-EventQueue-2] ERROR Vision.TemplateCanvas - Error invoking extension method.  
org.python.core.PyException: Traceback (most recent call last):  
File “”, line 14, in initializeTemplate  
NameError: global name ‘event’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getglobal(PyFrame.java:265)
at org.python.pycode._pyx3.initializeTemplate$1(<extension-method initializeTemplate>:17)
at org.python.pycode._pyx3.call_function(<extension-method initializeTemplate>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:376)
at org.python.core.PyFunction. __call__ (PyFunction.java:371)
at org.python.core.PyFunction. __call__ (PyFunction.java:361)
at org.python.core.PyFunction. __call__ (PyFunction.java:356)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:154)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._finishBuilding(TemplateCanvas.java:375)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$TemplateLoader.done(TemplateCanvas.java:314)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.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)

```

12:30:33.425 [AWT-EventQueue-2] ERROR Vision.TemplateCanvas - Error invoking extension method.  
org.python.core.PyException: Traceback (most recent call last):  
File “”, line 14, in initializeTemplate  
NameError: global name ‘event’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getglobal(PyFrame.java:265)
at org.python.pycode._pyx3.initializeTemplate$1(<extension-method initializeTemplate>:17)
at org.python.pycode._pyx3.call_function(<extension-method initializeTemplate>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:376)
at org.python.core.PyFunction. __call__ (PyFunction.java:371)
at org.python.core.PyFunction. __call__ (PyFunction.java:361)
at org.python.core.PyFunction. __call__ (PyFunction.java:356)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:154)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._finishBuilding(TemplateCanvas.java:375)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$TemplateLoader.done(TemplateCanvas.java:314)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.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)

```

12:30:33.428 [AWT-EventQueue-2] ERROR Vision.TemplateCanvas - Error invoking extension method.  
org.python.core.PyException: Traceback (most recent call last):  
File “”, line 14, in initializeTemplate  
NameError: global name ‘event’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getglobal(PyFrame.java:265)
at org.python.pycode._pyx3.initializeTemplate$1(<extension-method initializeTemplate>:17)
at org.python.pycode._pyx3.call_function(<extension-method initializeTemplate>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:376)
at org.python.core.PyFunction. __call__ (PyFunction.java:371)
at org.python.core.PyFunction. __call__ (PyFunction.java:361)
at org.python.core.PyFunction. __call__ (PyFunction.java:356)
at com.inductiveautomation.vision.api.client.components.model.ExtensionFunction.invoke(ExtensionFunction.java:154)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._finishBuilding(TemplateCanvas.java:375)
at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$TemplateLoader.done(TemplateCanvas.java:314)
at javax.swing.SwingWorker$5.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
at sun.swing.AccumulativeRunnable.run(Unknown Source)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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.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)

```

[/code][/details]

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 14, 2018, 12:07pm UTC](https://forum.inductiveautomation.com/t/updating-template-canvas-dataset-to-draw-dots/19672/2 "2018-09-14T12:07:41Z")

</div>

Take a closer look at your exception. It’s coming from the template, not the template canvas. Line 14 of initializeTemplate.

---

<div class="post-metadata">

**Author:** ![agn](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@agn](https://forum.inductiveautomation.com/u/agn)\
**Post date:** [September 14, 2018, 12:52pm UTC](https://forum.inductiveautomation.com/t/updating-template-canvas-dataset-to-draw-dots/19672/3 "2018-09-14T12:52:58Z")

</div>

This was embarrassing. THanks for pointing it out. I had previously put some code within the element itself as described.  
(Right Click-\>Scripting-\>InitializeTemplate).  
When removed it worked flawlesly.

Now I need to figure out how to call the script whenever an alarm is triggered and not by a timer.
