# Clear / Reset / Initialize UDTs in Script

**URL:** <https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084>\
**Category:** General Discussion\
**Created:** [February 28, 2014, 11:27pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084 "2014-02-28T23:27:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RMAC](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@RMAC](https://forum.inductiveautomation.com/u/RMAC)\
**Post date:** [February 28, 2014, 11:27pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/1 "2014-02-28T23:27:00Z")

</div>

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 = system.tag.read(“BlankUDT”)   
system.tag.write(“UDTToClear”,y)

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.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 3, 2014, 3:40pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/2 "2014-03-03T15:40:22Z")

</div>

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 = system.tag.read("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.

---

<div class="post-metadata">

**Author:** ![RMAC](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@RMAC](https://forum.inductiveautomation.com/u/RMAC)\
**Post date:** [March 3, 2014, 8:35pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/3 "2014-03-03T20:35:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 3, 2014, 9:17pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/4 "2014-03-03T21:17:07Z")

</div>

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](http://marketplace.inductiveautomation.com/moduledetail?4&moduleId=46) might work for you. These functions will be built in Ignition 7.7 as standard functions.

---

<div class="post-metadata">

**Author:** ![RMAC](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@RMAC](https://forum.inductiveautomation.com/u/RMAC)\
**Post date:** [March 4, 2014, 5:00pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/5 "2014-03-04T17:00:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RMAC](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@RMAC](https://forum.inductiveautomation.com/u/RMAC)\
**Post date:** [March 4, 2014, 5:08pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/6 "2014-03-04T17:08:35Z")

</div>

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 Scripting-module.zip to IA Labs Scripting-module.modl so Ignition can import it.

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

---

<div class="post-metadata">

**Author:** ![lstanczyk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lstanczyk/32/24686_2.png) [@lstanczyk](https://forum.inductiveautomation.com/u/lstanczyk)\
**Post date:** [July 12, 2023, 5:42pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/7 "2023-07-12T17:42:15Z")

</div>

Here is what I used to loop through all properties and set them to default values:

```auto
     slotTags = system.tag.browseTags(<your path root>,
					   tagPath=<your path>,
					   recursive=True,
					   sort="ASC")
	for slotTag in slotTags:
		childrenTags = system.tag.browseTags(slotTag.fullPath,
						   tagPath="*",
						   recursive=True,
						   sort="ASC")
		floatChildren = filter(lambda t: str(t.dataType)=="Float4",childrenTags)
		boolChildren = filter(lambda t: str(t.dataType)=="Boolean",childrenTags)
		stringChildren = filter(lambda t: str(t.dataType)=="String",childrenTags)
		integerChildren = filter(lambda t: str(t.dataType)=="Int4",childrenTags)
		
		system.tag.writeBlocking([t.fullPath for t in stringChildren], list([""] * len(stringChildren)))
		system.tag.writeBlocking([t.fullPath for t in boolChildren], list([False] * len(boolChildren)))
		system.tag.writeBlocking([t.fullPath for t in floatChildren], list([0.0] * len(floatChildren)))
		system.tag.writeBlocking([t.fullPath for t in integerChildren], list([0] * len(integerChildren)))

```

---

<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:** [July 12, 2023, 5:52pm UTC](https://forum.inductiveautomation.com/t/clear-reset-initialize-udts-in-script/8084/8 "2023-07-12T17:52:20Z")

</div>

You can make that a lot easier using TypeUtilities, see this post:

> [@Browse tags printing folder](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/20):
>
> from com.inductiveautomation.ignition.common import TypeUtilities # Grabs current Date and Time getDateTime = system.date.now() # Returns current hour in a 0-23 format getHour = system.date.getHour24(getDateTime) # Creates list to store tag paths paths = [] # Checks if time is Midnight if getHour == 7: # Gets all tags in folder sub structure and writes to an array tags = system.tag.browseTags(parentPath="folder", recursive = True) for tag in tags: if not tag.isFolder(): …
