# Moving the UDT Instance to the Another Folder Via Script,

**URL:** <https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552>\
**Category:** Ignition\
**Tags:** vision, scripting, ignition81\
**Created:** [May 22, 2025, 11:02am UTC](https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552 "2025-05-22T11:02:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [May 22, 2025, 11:02am UTC](https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552/1 "2025-05-22T11:02:19Z")

</div>

HI Folks,  
I want to move the Memory Tag "MYTag" from the UDT Definition "My Definition 1" to "My Definition 2". Once the tag is successfully added to "My Definition 2", it should be removed from "My Definition 1".  
I’m executing the script in the Script Console, and I’ve written a script to get both UDT configurations, extract the tag, transfer it, and apply changes using system.tag.configure().

 ![WhatsApp Image 2025-05-21 at 9.50.12 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/6/e60f5ceec4dcb865cff32ce3ab46011bb6655e44.jpeg)

--\>Script:  
from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

```python
try:
	fromPath = "[default]types/My Definition 1"
	toPath = "[default]types/My Definition 2"
 
	# Get UDT definitions
	fromDef = system.tag.getConfiguration(fromPath, True)[0]
	toDef = system.tag.getConfiguration(toPath, True)[0]
 
	# Extract internal tags
	fromTags = fromDef.get("tags", [])
	toTags = toDef.get("tags", [])
 
	# Find and remove MYTag
	tagToMove = None
	newFromTags = []
	for tag in fromTags:
		if tag.get("name") == "MYTag":
			tagToMove = tag
		else:
			newFromTags.append(tag)
 
	if tagToMove is None:
		print("MYTag not found.")
	else:
		toTags.append(tagToMove)
		fromDef["tags"] = newFromTags
		toDef["tags"] = toTags
 
		fromDef["path"] = fromPath
		toDef["path"] = toPath
 
		# Correct usage: convert string to TagPath
		basePath = TagPathParser.parse("[default]types")
		system.tag.configure(basePath, [fromDef, toDef], "m")
 
		print("MYTag successfully moved from My Definition 1 to My Definition 2.")
 
except Exception as e:
	import sys
	print("Error:", str(e))
	sys.printException(e)

```

--\> i am getting the error message as well "MYTag successfully moved from My Definition 1 to My Definition 2. ", but nothing is moved.

--\>this is the error message:

> > >

[Error\_Configuration("java.lang.ClassCastException: class java.lang.String cannot be cast to class com.inductiveautomation.ignition.common.tags.model.TagPath (java.lang.String is in module java.base of loader 'bootstrap'; com.inductiveautomation.ignition.common.tags.model.TagPath is in unnamed module of loader java.net.URLClassLoader @3099f5ed)"), Error\_Configuration("java.lang.ClassCastException: class java.lang.String cannot be cast to class com.inductiveautomation.ignition.common.tags.model.TagPath (java.lang.String is in module java.base of loader 'bootstrap'; com.inductiveautomation.ignition.common.tags.model.TagPath is in unnamed module of loader java.net.URLClassLoader @3099f5ed)")]  
MYTag successfully moved from My Definition 1 to My Definition 2.

> > >

can u please look in to this issue and provide a fix.

Regards,  
Adarsh R S`Preformatted text`

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 22, 2025, 1:57pm UTC](https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552/2 "2025-05-22T13:57:23Z")

</div>

`system.tag.configure(basePath, [fromDef, toDef], "m")`

This should be

`system.tag.configure(basePath, {'tags': [fromDef, toDef]} , "m")`

There might be something else as I haven't tested it. You also don't need the tag parser, you can set the basePath to just `"[default]_types_"`

Actually, youre using `"types"` instead of `"_types_" `

---

<div class="post-metadata">

**Author:** ![vtran](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vtran](https://forum.inductiveautomation.com/u/vtran)\
**Post date:** [May 22, 2025, 2:21pm UTC](https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552/3 "2025-05-22T14:21:29Z")

</div>

Don't have a gateway to test with right now, but I think it would be something like this, might need some troubleshoot if I messed up any syntax.  
Also:

- You only need to read the config of the original UDT
- `basePath` parameter for `system.tag.configure` can just be a string
- backup your tags before testing 😆

```python
fromPath = "[default]_types_/My Definition 1"
toPath = "[default]_types_/My Definition 2"

# get tags to move
fromDef = system.tag.getConfiguration(fromPath, True)[0]
tagsToMove = fromDef['tags'] 

# copy the tags to the new location
system.tag.configure(toPath, tagsToMove, 'm')

# check to make sure tags are there
good = True
for tag in tagsToMove:
  newPath = "%s/%s" % (toPath, tag['name'])
 # if any new path doesn't exis
  if not system.tag.exists(newPath):
    good = False
    break
# if all tags are moved, empty out the original UDT
if good:
  # empty out the tags from the original config
  fromDef['tags'] = []
  # overwrite original with empty tags def
  system.tag.configure("[default]_types_", [fromDef], "o")
 

```

---

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [June 10, 2025, 2:40pm UTC](https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552/4 "2025-06-10T14:40:49Z")

</div>

Hello everyone,

Currently, the provided code is working, but it moves all tags from the source to the destination.  
I would like the code to move only the old tag(in the folder only first tag) from the source to the destination.  
Please do needfull

Thanks for advance.  
Adarsh R S

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 10, 2025, 2:51pm UTC](https://forum.inductiveautomation.com/t/moving-the-udt-instance-to-the-another-folder-via-script/106552/5 "2025-06-10T14:51:42Z")

</div>

> [@Adarsh\_Shelar](#):
>
> would like the code to

Then study it to learn how it works, and modify it for your needs.

> [@Adarsh\_Shelar](#):
>
> Please do needfull

We aren't your staff. We are volunteers, offering help. You are expected to do your own homework.
