# Flex Repeater Script Instance Additions

**URL:** <https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155>\
**Category:** Ignition Early Access\
**Tags:** perspective\
**Created:** [September 10, 2019, 8:37pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155 "2019-09-10T20:37:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [September 10, 2019, 8:37pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/1 "2019-09-10T20:37:21Z")

</div>

I am trying to figure out how to dynamically add instances to a flex repeater in a Perspective View.  
I've not seen much in the way of how to do this, but the one thread seemed to indicate there may be a bug in the functionality or not yet added functionality. [Link](http://forum.inductiveautomation.com/t/feature-13532-oob-exception-when-trying-to-append-to-a-flex-repeaters-prop-instances/26454)

I did use the tolist() method to print the content of my one instance (manually entered) to the system log. This is what that looked like:  
QV[{displayVal=[value, Good\_Unspecified, Wed Dec 31 18:00:00 CST 1969 (941)], instancePosition=QV[{}, Good\_Unspecified, Wed Dec 31 18:00:00 CST 1969], instanceStyle=QV[{classes=[, Good\_Unspecified, Wed Dec 31 18:00:00 CST 1969 (941)]}, Good\_Unspecified, Wed Dec 31 18:00:00 CST 1969]}, Good\_Unspecified, Wed Dec 31 18:00:00 CST 1969]  
I'm not sure what to make of that output!  
The actual Instance of the Flex Repeater looks like the attached image.  
 ![FRInstance](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/17f94052d13da28e972e93a6ade79767a2d2071a.png)

So, how can a script be used to add instances to a Flex Repeater? What about SQL Queries, would they have to be wrapped in a script or is there a way to directly populate instances using queries? What other ways are there to dynamically populate these?

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [September 10, 2019, 9:03pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/2 "2019-09-10T21:03:49Z")

</div>

Here’s what I ended up doing to programatically add instances; I run this in a message handler on my FlexRepeaters.

```auto
# Check if the instances list is empty.
# If the instances list is empty, create a new list. Otherwise, load the current list.
if (self.props.instances == None):
	currentInstances = []
else:
	currentInstances = self.props.instances.tolist()
		
newInstance = {
	# Put your instance properties here.
	}
	
currentInstances.append(newInstance)
	
self.props.instances = currentInstances

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 10, 2019, 9:11pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/3 "2019-09-10T21:11:33Z")

</div>

> [@MikeAllgood](#):
>
> What about SQL Queries, would they have to be wrapped in a script or is there a way to directly populate instances using queries?

Rather than directly manipulating the query into the right output format, you would probably be best served with a script transform that takes the query output and manipulates it into the required shape.

Also, regarding the odd script output and (imo) weird behavior of tolist, I actually just submitted changes yesterday that make the property trees _much_ more friendly to script around; for instance, you can just directly `append()` a dictionary to them, and it will automatically wrap it into the required shape.

---

<div class="post-metadata">

**Author:** ![colin.blue](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@colin.blue](https://forum.inductiveautomation.com/u/colin.blue)\
**Post date:** [June 14, 2021, 5:12pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/4 "2021-06-14T17:12:01Z")

</div>

Could you please elaborate on the changes you submitted, and specifically how this will help with dynamic instance creation for the view canvas in perspective?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 14, 2021, 6:06pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/5 "2021-06-14T18:06:17Z")

</div>

This was almost 2 years ago, but basically property trees pretend to be native Python data structures much better now - you can use standard Python dictionary methods on them, update them with the values from standard python dictionaries, etc. So you don’t (in theory) need to use any hidden conversion methods - you just make the dictionary form of whatever properties you want, then directly return it from your transforms/etc.

---

<div class="post-metadata">

**Author:** ![colin.blue](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@colin.blue](https://forum.inductiveautomation.com/u/colin.blue)\
**Post date:** [June 14, 2021, 6:23pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/6 "2021-06-14T18:23:26Z")

</div>

Thank you for getting back with me. I don’t quite understand how to reference the instance properties of the view canvas in the dictionary. Does the path to a particular property go on the left side of the colon in a dictionary entry?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 14, 2021, 6:41pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/7 "2021-06-14T18:41:05Z")

</div>

So the gist of it is that you want to return a well formed _array_ of _objects_ for the `instances` parameter of the View Canvas. Each of those objects in the array should have (at least some of) the keys from the list here: [Perspective - View Canvas - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+View+Canvas)

So, what I would generally recommend doing is binding `instances` (the root property) to whatever your dynamic data source is (if you have one) - your query, tag, property, whatever. Then add a script transform to it, which returns that list of dictionaries with the right property ‘shape’ for the view canvas:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7a327162905d63b2e91aa169429f95f453121054.png)

```python
	return [
	{
		"position": "relative",
		"top": str(i * 100) + "px",
		"viewPath": "inner",
		"viewParams": {
			"label": name
		},
		"left": "0px",
		"bottom": "auto",
		"right": "auto",
		"zIndex": "auto",
		"width": "auto",
		"height": "auto",
		"style": {},
	}
	for i, name in enumerate(value)
	]

```

In this case my script is obviously not doing a whole lot, because my input array is very simple, but if you had a query binding bringing in a dataset you’d likely have a lot more parameters to pass in.

---

<div class="post-metadata">

**Author:** ![vani161998](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vani161998](https://forum.inductiveautomation.com/u/vani161998)\
**Post date:** [March 10, 2022, 6:43am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/8 "2022-03-10T06:43:09Z")

</div>

how can remove the added instances using message handler?

---

<div class="post-metadata">

**Author:** ![suram-in](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/suram-in/32/51348_2.png) [@suram-in](https://forum.inductiveautomation.com/u/suram-in)\
**Post date:** [September 6, 2023, 4:42pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/9 "2023-09-06T16:42:51Z")

</div>

Is it possible to add this script in the Root of the View like Configure Events-\>System Events-\>onStartup?

The idea is instead of binding I will create the instances from the scripting while opening the pop up.

Is there any way to create instances based on the script outcome results.?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 9, 2023, 1:52pm UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/10 "2023-09-09T13:52:56Z")

</div>

Why would you want to do this ?  
What’s the use case that would make you want not to use bindings ?

---

<div class="post-metadata">

**Author:** ![suram-in](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/suram-in/32/51348_2.png) [@suram-in](https://forum.inductiveautomation.com/u/suram-in)\
**Post date:** [September 11, 2023, 5:19am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/11 "2023-09-11T05:19:26Z")

</div>

My Input Array is the Dynamic one. I used the Canvas Template Repeater in Ignition. Here is the code I used during startup the windows.

```
	# get the numbers of the Interlocks for the each type
	intlresults = system.tag.browse(mtrpath+'/Interlocks', {'typeId': 'PointType/AcesysV8INTL'})
	intlcount = intlresults.getReturnedSize()
	
	# Interlocking Title
	if intlcount > 0:
		row = ['INTLTitle','Title','{"TitleText":"Interlocking"}','0','0','0','0','Wrap','0']
		intldata.append(row)
	
		# Interlocking Data
		for intlresult in intlresults.getResults():
			intlfullpath = intlresult['fullPath']
			dummyintl = dummyintl + 1
			intlparam = '{"Tag_Path":"' + str(intlfullpath) + '"}'
			intlname = 'INT' + str(dummyintl)
			row = [intlname,"Interlock",intlparam,"0","0","0","0","Wrap","0"]
			intldata.append(row)

```

like this I have more data then finally

```
	# Finally Set the pydataset to Canvas Template dataset				
	system.gui.getParentWindow(event).getComponentForPath('Root Container.Interlock Container.Interlock Canvas').templates = system.dataset.toDataSet(intlheaders,intldata)

```

I am trying to convert this code to the perspective. Here intlcount is the dynamic one. I am trying to find the tag path of the specified UDT type and binding to the canvas.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 11, 2023, 7:13am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/12 "2023-09-11T07:13:18Z")

</div>

You're talking about a vision component in a thread about a perspective component. This is not the way.

Make a new post about your issue, and tag it properly.

edit: A few tips for when you make this new post:

- create it in the `ignition` section, not here
- describe your problem, not how you're trying to solve it. I can almost guarantee the solution will be to use a binding, not a startup script.

---

<div class="post-metadata">

**Author:** ![joshdunstan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joshdunstan/32/43306_2.png) [@joshdunstan](https://forum.inductiveautomation.com/u/joshdunstan)\
**Post date:** [September 21, 2023, 11:31am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/13 "2023-09-21T11:31:20Z")

</div>

Here I was thinking.. wait.. what! There's a flex repeater canvas on perspective now!? I shall continue with nested views.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 21, 2023, 11:51am UTC](https://forum.inductiveautomation.com/t/flex-repeater-script-instance-additions/28155/14 "2023-09-21T11:51:29Z")

</div>

There's this, though:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/9/99aee1f29b32390dfc9c51a0aada25197964ca2f.png)

It's called view canvas but is pretty much the equivalent of the flex repeater for coordinate containers.
