Clear / Reset / Initialize UDTs in Script

Does anyone know how to clear or reset memory tag UDTs to default in Python? I would also be happy copying a blank UDT into the UDT I am tying to clear. I’m trying to clear out a recipe UDT before populating it from a DB transaction that may be incomplete or may not contain all the recipe steps. Ignition does not seem to be happy with system.tag.write() with a UDT. I need a system.UDT.write() or equivilent.

Here is what I have tried
y =“BlankUDT”)

I’m hoping not to have to blow it out into a dataset and reassemble if possible.
This is a recipe editor located all in Ignition memory UDTs and DB so I can not clear it at the PLC level.

I’m not having any trouble writing to a memory tag that’s part of a UDT. Here’s what I did.

I have a UDT that contains a memory tag named “Memory_tag_int”. That memory tag is data type int4, is enabled, and has read/write access rights. I made an instance of that UDT, called mem_instance. Note that if I try to write just to mem_instance, I get an error. This is because your UDT instance could contain lots of tags, and Ignition wouldn’t have a clue which one you meant to write to. Instead, I have to write to the memory tag contained inside mem_instance.

The following script will increment that tag by 1 every time it’s clicked.temp ="mem_instance/Memory_tag_int") system.tag.write("mem_instance/Memory_tag_int", temp.value+1)Remember, since read returns a qualified value, you need to get the value member from the object read returns. If you try to use just ‘temp+1’, you’ll also get an error.

I’m not trying to write to a single element of a UDT. I’m trying to ethier initialize an entire UDT to its defaults or write a already blanked out UDT into the UDT I’m trying to clear. The UDT I’m trying to clear contains around 600 elements with multiple sub UDTs.

Ah, much clearer now.

Would removing the tag and adding a new instance with the same name work for you? If so, the new system.tag scripting functions in the free IALabs Scripting Module might work for you. These functions will be built in Ignition 7.7 as standard functions.

Thanks Kathy, it works great.

Here is my implementation:

Clear steps in editor

system.tag.removeTag(“Compression/Recipe Edit/Recipe”)
system.tag.addTag(parentPath=“Compression/Recipe Edit”, name=“Recipe”, tagType=“UDT_INST” attributes={“UDTParentType”:“CompressionRecipeEdit”})

I’m not sure I would want to use this technique on a tag that was looked at asynchronously such as trending or OPC to prevent errors. Is there any plans to add capability to copy entire UDTs (UDTa = UDTb) as well as subsets (UDTa/Step15 = UDT_Step)? Initializing a UDT could also be handy but could be worked around by copying a blank UDT into the one to be cleared. I see this functionality giving Ignition significant more power in data manipulation.

One more hint for others installing IA Labs Scripting Module:

When you download the module it may come as a ZIP file. If so, rename it from IA Labs to IA Labs Scripting-module.modl so Ignition can import it.

This is not in the instructions and could stump some of you.