# "Dynamic" UDT instance

**URL:** <https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 15, 2022, 10:00am UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787 "2022-06-15T10:00:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 10:00am UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/1 "2022-06-15T10:00:59Z")

</div>

Hi,

For the moment, I have an UDT that we can call PlantUDT, which possesses several parameters and 2 folders : MachineA and MachineB, which contains all the tags.

But now, I would like to make the number of MachineA and MachineB dynamic, depending on the plant. I though about modifying the UDT PlantUDT to that it possesses only the actual parameters with 2 other parameters : NumberOfMachineA and NumberOfMachineB, so that at the moment of the instanciation of the UDT, I can put the right values in these two parameters and the UDT “automatically” imports the necessary number of MachineA and MachineB instances.

Examples :

- A first plant “Plant1” possess 1 MachineA and 2 MachineB. Then I want to create an instance of PlantUDT and to configure NumberOfMachineA=1 and NumberOfMachineB=2, so that it imports 1 instance of MachineA et 2 instances of MachineB.
- But a second plant “Plant2” have 3 MachineA et 1 MachineB, so for this plant I have to create another instance of PlantUDT and to configure NumberOfMachineA=3 and NumberOfMachineB=1, so that it imports 3 instances of MachineA et 1 instances of MachineB.

Is it possible ?

Thanks,

Carla

---

<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:** [June 15, 2022, 10:36am UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/2 "2022-06-15T10:36:33Z")

</div>

Where/how do you get your machines information ?

I’d make UDTs for `machineA` and `machineB`, possibly only one UDT depending on how different those machines are.  
Then make a script using `system.tag.configuration` to create the instances depending on your machines data source (maybe a json, an xml… whatever it is).

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 11:59am UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/3 "2022-06-15T11:59:12Z")

</div>

My machines informations come from a MQTT server.

> [@pascal.fragnoud](#):
>
> make a script using `system.tag.configuration`

And I put this script in the "Scripting" module of Ignition, maybe on the Gateway Startup Event section ? Or is that not wise ?

---

<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:** [June 15, 2022, 12:23pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/4 "2022-06-15T12:23:33Z")

</div>

Can you give us more details about how/when you receive that data and process it ?

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 12:48pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/5 "2022-06-15T12:48:23Z")

</div>

Of course.

Well, we are using SCADA which are connected to the automaton. These SCADA get and display the data, and they also send the data to Ignition via a MQTT server. Then, on the designer of Ignition, the data are stored here (we can say that Filtration\_CLO2=MachineA, Filtration\_H2O2=MachineB, I gave generic name not to be too much specific) :

![MQTT](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/6/266b17ecfc43e2e1f1213a5e4a05a5f730bf99e3.png)

And the tags are located in these two folders. For example, the tag “Cycles” is located here :

![cycles](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/6/369a085bee3cdc6a579bee92650a53257a15fb53.png)

and then in my UDT I create a reference tag where I give the path of the tag (with “UDTName” a parameter that changes for each client) :

![UDT](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/9/e97a1f1aa338a266449fe97d414abfbda3ae58bf.png)

Same thing for all the tags. Then, when I create an instance of this UDT specifying the value of the missing parameters, I can access the value of the tags.

Is it a little bit clearer ?

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 12:58pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/6 "2022-06-15T12:58:15Z")

</div>

And the data are received every 30s

---

<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:** [June 15, 2022, 1:23pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/7 "2022-06-15T13:23:57Z")

</div>

> [@Carla\_Ratto](#):
>
> Is it a little bit clearer ?

Yes, it is. If I understand correctly, your MQTT Engine is/acts as a remote tag provider, and it has a folder for each machine you want to add to your `UDT_Filtration`. Correct ?

How often do you expect the machines to change ?  
Can they only be added, or can they also be removed ?  
What does it look like (in the MQTT Engine tags) when there are several machines of the same type ?

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 1:34pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/8 "2022-06-15T13:34:24Z")

</div>

> [@pascal.fragnoud](#):
>
> Correct ?

Yes, that's it !

> [@pascal.fragnoud](#):
>
> How often do you expect the machines to change ?

Well, on a given plant, the machines won't change (or it will be very rare). The thing is that each plant has his own architecture, a small plant will have only 2 machines, while a bigger plant could have 6 for instance. So, the idea is that we look at the architecture of the client, and in function of this architecture we configure the UDT for the right number of machines.

> [@pascal.fragnoud](#):
>
> What does it look like

For the moment we are only testing our interface for this plant so we don't really know but I though about giving a different name to all the machines of the same type so that there is no conflict between the data (for example CLO2\_Filtration\_1 and CLO2\_Filtration\_2 if there are two CLO2 machines).

---

<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:** [June 15, 2022, 1:41pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/9 "2022-06-15T13:41:04Z")

</div>

> [@Carla\_Ratto](#):
>
> on a given plant, the machines won’t change (or it will be very rare)

How about having a manually run script that imports that configuration, then ?

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 1:50pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/10 "2022-06-15T13:50:38Z")

</div>

Yes I guess it could work, but where should I write this script ? Also, does it seems possible using `system.tag.configuration` ?

---

<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:** [June 15, 2022, 2:05pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/11 "2022-06-15T14:05:22Z")

</div>

You can have a protected view on the project, with a button that would run the script.

It would look something like that:

```python
def update_machines():
	# If that folder can contain other things than just machine folders, add a filter
	mqtt_machines = system.tag.browse("[MQTT Engine]Edge Nodes/Mountoun")
	current_machines = system.tag.browse("[]path/to/UDT_Filtration")

	# Compare those to figure out what machines you want to add to your current configuration
	# How to do that will depend on what it looks like when there are several machines
	new_machines = compare(mqtt_machines, current_machines)

	# Create each machine tag, you'll have to figure this out based on the data you have,
	# this is only an example
	new_machines_tags = [
		{
			'name': m['name'],
			'tagType': "UdtInstance",
			'typeID': "CLO2" if "CLO2" in m['name'] else "H2O2",
			'parameters': m['parameters']
		} for m in new_machines
	]

	system.tag.configure("[]path/to/UDT_Filtration", new_machines_tags, 'm')

```

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 15, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/12 "2022-06-15T14:43:48Z")

</div>

Oook I think I see the idea, I’ll work on it. I’ll do an update when I get that working. Thanks a lot !

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 23, 2022, 3:06pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/13 "2022-06-23T15:06:50Z")

</div>

Hi, sorry for the delay, I had others things to do this week.  
I worked on it today, and I just would like to check something to be sure I’m not going in the wrong way.

I created a view where the user can enter the name of the client and click on a button to browse the mqtt tags associated to this client. Then, a component appears to allow the user to enter the udt parameters, and ones its done, it is possible to create the UDT Definition and its instance by clicking on another button.

But as tags and UDTs are shared with all projects, if I modify the general UDT Definition it will modify it on all projects. Then, it means that I have to create as many UDT Definitions than than clients (since all clients don’t have the same machines number), that’s right ? I’ve been thinking about other ways to do using folders or anything but as I’m using the dropConfig property to create views instances I’m obliged to use UDT. Then I think it is the only way to do this, but I prefer to be sure before spending too much time working on a bad solution.

Thanks in advance 🙂

---

<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:** [June 23, 2022, 3:22pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/14 "2022-06-23T15:22:01Z")

</div>

By client, do you mean customer, or a user-client, like a browser ?

if you mean customer, you shouldn’t share tags and UDTs between your different customers. Making different tag providers seems a more secure way to do this, and then the issue you just described just disappear, since each tag provider will have its own UDTs.

---

<div class="post-metadata">

**Author:** ![Carla\_Ratto](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Carla\_Ratto](https://forum.inductiveautomation.com/u/Carla_Ratto)\
**Post date:** [June 23, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/dynamic-udt-instance/60787/15 "2022-06-23T15:29:59Z")

</div>

By client I mean each installation for which I have to create an interface, which therefore needs a particular instance of the udt and also of the page.

Effectively making different tag providers seems to be a good solution, I didn’t thought about that. Thanks for your advice 🙂
