# Method to Create UDT Definition

**URL:** <https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624>\
**Category:** Ignition\
**Created:** [August 11, 2020, 8:35pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624 "2020-08-11T20:35:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [August 11, 2020, 8:35pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/1 "2020-08-11T20:35:14Z")

</div>

Is there a method to create UDT definitions in code? If so does anyone have and example?

---

<div class="post-metadata">

**Author:** ![JantjeBeton](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@JantjeBeton](https://forum.inductiveautomation.com/u/JantjeBeton)\
**Post date:** [October 25, 2022, 10:56am UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/2 "2022-10-25T10:56:30Z")

</div>

I would be interested as well...  
If I get the configuration of an existing UDT and use it to create another with a different name, I get an atomic tag not a structure.. Any suggestions?

---

<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:** [October 25, 2022, 2:03pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/3 "2022-10-25T14:03:24Z")

</div>

This works for me:

```python
foo = system.tag.getConfiguration("[Test]_types_/Foo", recursive=True)
foo[0]['name'] = "Bar"
system.tag.configure("[Test]_types_", foo, 'o')

```

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [October 25, 2022, 2:33pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/4 "2022-10-25T14:33:51Z")

</div>

Can also create them from L5K file export

> **[Ignition Exchange](https://www.inductiveautomation.com/exchange/2114/overview)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

---

<div class="post-metadata">

**Author:** ![JantjeBeton](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@JantjeBeton](https://forum.inductiveautomation.com/u/JantjeBeton)\
**Post date:** [October 31, 2022, 3:08pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/5 "2022-10-31T15:08:30Z")

</div>

> [@pascal.fragnoud](#):
>
> This works for me:
> 
> ```python
> foo = system.tag.getConfiguration("[Test]_types_/Foo", recursive=True)
> foo[0]['name'] = "Bar"
> system.tag.configure("[Test]_types_", foo, 'o')
> 
> ```

Hi Pascal,

Thanks for your reply. Yes this works for me as well!  
However what we try to achieve is to create an UDT from scratch in scripting, therefore storing the structure in a variable..

To demonstrate the difficulties we encounter, I've used your example and added a print and second import after modifying the path with exactly the same (string) value.  
This won't work however.. See the console output below:

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

What am I missing here?

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [October 31, 2022, 8:49pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/6 "2022-10-31T20:49:33Z")

</div>

Why would you write to 'path' as it should be basePath ("[Default]\_types \_") + name?

---

<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:** [October 31, 2022, 8:53pm UTC](https://forum.inductiveautomation.com/t/method-to-create-udt-definition/37624/7 "2022-10-31T20:53:01Z")

</div>

> [@JantjeBeton](#):
>
> To demonstrate the difficulties we encounter

This only demonstrate that what you're trying to do is not supported, though I'm not sure what it is that you hoped to achieve by changing the `path` attribute of a tag ?

If you want to create a UDT from scratch, just pass a dict with the key/values pairs that are relevant to `system.tag.configure`. Don't worry about the path.

```python
new_udt = {
    'name': "Foo",
    'typeId': "Foo",
    'tagType': "UdtType",
    'parameters': {
        'bar': 1,
        'baz': 42
    },
    'tags': [
        {
            # add tags here
        }
    ]
}
system.tag.configure("_types_", foo)

```
