Method to Create UDT Definition

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

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?

This works for me:

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

Can also create them from L5K file export

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:

What am I missing here?

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

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.

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