# Get Parent (or Parent of Parent) Relative Tag Name

**URL:** <https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141>\
**Category:** General Discussion\
**Created:** [January 29, 2016, 3:01am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141 "2016-01-29T03:01:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://forum.inductiveautomation.com/u/ian)\
**Post date:** [January 29, 2016, 3:01am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/1 "2016-01-29T03:01:56Z")

</div>

In Ignition, is there a way to get the Parent Tag name?

Suppose I have a Tag: (1) A/B0/C and (2) A/B1/C, can I get A/B0 path and A/B1 path from C with the same script (scripted in its UDT class)?

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://forum.inductiveautomation.com/u/ian)\
**Post date:** [January 29, 2016, 4:25am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/2 "2016-01-29T04:25:09Z")

</div>

Or else, is there any way to get Parent (or Parent of Parent) Relative Tag Parameter?

Here is for illustration:

I have tags with paths like:

A/B0/C/D  
A/B1/C/D  
A/B2/C/D  
A/B3/C/D

Thus, I only need to put Number in my B tags as Data Type Parameter. However, I do not know how to access B Data Type Parameter from D. I could easily get D’s (assuming D is Expression Tag) Data Type Parameters in its Expression like this {Number}, but how to get C’s or B’s?

Since each C is another UDT owned by each B, I don’t know if we could get relative parent Parameters. I know that we could get our own custom parameters which are very useful indeed. But how to get the parent’s (or the parent’s parent’s). Is there a way to automatically pass down this custom parameter to all its children and its children’s children? Like inheritance protected concept in OOP like C# or Java I mean.

Any workaround? ☹

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://forum.inductiveautomation.com/u/ian)\
**Post date:** [February 18, 2016, 2:09am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/3 "2016-02-18T02:09:57Z")

</div>

I am trying to clarify the question here even further (hope it may help. Better question format can be seen [here](http://stackoverflow.com/questions/35471431/ignition-get-parent-and-parent-of-parent-relative-tag-paths-names).):

In Ignition, is there a way to get Parent and Parent of Parent relative tag names from an Expression Tag who is a member of a UDT tag in its definition?

Here is the case, I have a UDT tag which contain some other built-in tags, and one of them is an Expression Tag, but the UDT tag is owned by some other higher UDT tag

Something like this (note: all these are in the UDT definition/“template”, not UDT instance):

```
MyBaseUDTTag
--MyExpressionTag
--SomeOtherTag    

```

And then the MyBaseUDTTag is owned by some other UDT tag

```
MyAdvanceUDTTag
--MyBaseUDTTagMember
--MyOtherTagMemberInAdvanceUDT

```

Then, in the MyExpressionTag of MyBaseUDTTag I want to create an expression which is based on its Parent of Parent (that is MyAdvanceUDTTag) custom properties, because in the Tag Browser I have instances of the MyAdvanceUDTTag whose paths are something like this:

```
BaseFolder/MyAdvanceUDTTagInstance0
BaseFolder/MyAdvanceUDTTagInstance1
BaseFolder/MyAdvanceUDTTagInstance2
BaseFolder/MyAdvanceUDTTagInstance3

```

Note that there are running numbers from 0-3 there. And I want to make those running number part of the Expression in MyExpressionTag, which - in term of tag paths - are the “child of child” of a particular MyAdvanceUDTTagInstance:

```
BaseFolder/MyAdvanceUDTTagInstance0/MyBaseUDTTagMember/MyExpressionTag
BaseFolder/MyAdvanceUDTTagInstance1/MyBaseUDTTagMember/MyExpressionTag
BaseFolder/MyAdvanceUDTTagInstance2/MyBaseUDTTagMember/MyExpressionTag
BaseFolder/MyAdvanceUDTTagInstance3/MyBaseUDTTagMember/MyExpressionTag

```

And so, to avoid definition for each individual tag, I want to make one Expression in the MyExpressionTag Definition/Template instead.

Here, I realize that we could get:

1. Parent UDT Custom Parameters + InstanceName + TagName
2. Fellow child’s tag value (that is: SomeOtherTag value)
3. A particular tag instance value - by specifying the path (which is quite close!)

Option 3. is actually quite close, but unfortunately not what I am looking for. Since what I look for is the name of that Tag - that is, MyAdvanceUDTTagInstance0 name, instead of MyAdvanceUDTTagInstance0 value.

Is there any way to do this in Ignition? I use Ignition v7.8.1 if that matters.

I only need to get Parent path/instance name (as string):

```
BaseFolder/MyAdvanceUDTTagInstance0/MyBaseUDTTagMember

```

And (more especially) parent of parent path/instance name:

```
BaseFolder/MyAdvanceUDTTagInstance0

```

Having OOP programming background with tools like WinForm, typically there is a way to get Parent Control and its name, and so I am hoping that there might be a similar approach to Ignition Tags too - which I am yet to know.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [February 18, 2016, 7:56pm UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/4 "2016-02-18T19:56:16Z")

</div>

You can use the split and rsplit functions to parse your string into a dataset and then reference the different parts. You can use slicing if you know the lengths too.

There isn’t anything built-in that will do what you want I don’t thing.

```auto
s='BaseFolder/MyAdvanceUDTTagInstance0/MyBaseUDTTagMember/MyExpressionTag'

print 'rsplit result'
print s.rsplit("/",1)
print s.rsplit("/",2)
print s.rsplit("/",3)

print 'cutting result'
print s[0:54]
print s[0:10]
```

There is probably a million ways to parse strings in Python.

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://forum.inductiveautomation.com/u/ian)\
**Post date:** [February 22, 2016, 5:10am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/5 "2016-02-22T05:10:13Z")

</div>

@MMaynardUSG

That seems to be the answer I am looking for! 😃 thanks, I will check it out.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [April 25, 2017, 9:32pm UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/6 "2017-04-25T21:32:42Z")

</div>

Is there a way to get a Parent Parameter when defining the Child UDT tag?  
For instance i have a parameter “Tag Name” on both UDT’s, but i want to access the PARENT “Tag Name” parameter not the Child.

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [April 26, 2017, 2:01am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/7 "2017-04-26T02:01:44Z")

</div>

In the parent UDT make an expression tag that contains what you need in the child udt tag.  
If that is tag name, you can use “{InstanceName}” so it is dynamic and isn’t actually set with a parameter.

Then from the child UDT you can create an expression tag that references {[.]…/parentUDTtagname}

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [April 26, 2017, 2:07am UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/8 "2017-04-26T02:07:41Z")

</div>

So you’d have to create an expression tag for every Parent UDT Parameter you are interested in accessing in the Child? That seems pretty excessive when the parameters are already defined.

---

<div class="post-metadata">

**Author:** ![MattJones](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@MattJones](https://forum.inductiveautomation.com/u/MattJones)\
**Post date:** [June 27, 2024, 8:44pm UTC](https://forum.inductiveautomation.com/t/get-parent-or-parent-of-parent-relative-tag-name/11141/9 "2024-06-27T20:44:37Z")

</div>

Came across this today but also found that some new Ignition parameters that made this much easier: [UDT Parameters | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/user-defined-types-udts/udt-parameters)

In my case I wanted to get the name of the folder that my UDT was placed in. I'm sure my folder structure will change in the future, so I used the code below to have the UDT calculate what the immediate parent folder would be. Adjust '3' to the correct depth of your tag in your UDT.

```python
split({PathToParentFolder}, "/")[len(split({PathToParentFolder}, '/')) - 3, 0]

```

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