# Accessing tag custom properties through scripting

**URL:** <https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [August 29, 2022, 7:15pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579 "2022-08-29T19:15:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [August 29, 2022, 7:15pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579/1 "2022-08-29T19:15:14Z")

</div>

What would be the syntax if I’m looping through the tags through scripting instead of a change script? Here is what I’m using now (that seems slow-ish when I’m testing in the script console):

```python
rootPath = "[TP]Folder/InnerFolder/Section"
pressTags = system.tag.browse(rootPath, {})

instances = []

for tag in pressTags:
	obj = {
		"title": tag["name"],
		"instances": map(lambda x: {"label": x["name"], "tagValue": x["fullPath"], "units": system.tag.getConfiguration(x["fullPath"])[0]["Units"]}, system.tag.browse(str(tag["fullPath"]) + "/Overview"))
	}
	instances.append(obj)

print instances

```

The custom property is called `Units` and is defined on the UDT of the tags inside the `Overview` folder. If I do a `system.tag.browse()` to a tag within `Overview`, I don’t get any custom properties so I’m using `system.tag.getConfiguration()` (I could also use `system.tag.read*`).

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 29, 2022, 7:42pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579/2 "2022-08-29T19:42:38Z")

</div>

I can imagine it is slow, beings as you are calling `system.tag.browse()` which is already a slow-ish function for every tag at the root path.

Instead, you should use the filter to filter for only the tags that you need and do so recursively, then you can loop through that list adding your custom property where needed building a list of tag paths, then read all of the tags at once.

Also, it looks like you are adding `"/Overview" to the full path of a tag, however, the full path includes the tag name, so unless the "tag" is a folder, then that path would be invalid.

I guess I don't understand your tag structure, so I can't really provide useful code, but I would expect you to build a list of all tags to be read, then split that into two lists as you can count on the order, and then build your instances list from that.

Here is another thread that shows something similar to what I would expect, note not all of this applies, you can pretty much ignore the DB stuff for your purposes.

> [@Gateway timer script to log folder of tags to SQL](https://forum.inductiveautomation.com/t/gateway-timer-script-to-log-folder-of-tags-to-sql/61180/25):
>
> Taking some inspiration from @JordanCClark I did my best to refactor your code to accomplish what you’re attempting to do. First here’s a little helper function which comes in handy for things like this. Technically you don’t need a function, but I find that grouper(2,zip(list1,list2)) is much more readable than zip(\*[iter(zip(list1,list2))] \* 2). Some may disagree. def grouper(n, iterable): return zip(\*[iter(iterable)] \* n) This will group elements of an iterable in into groups of ‘n’…

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [August 29, 2022, 8:12pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579/3 "2022-08-29T20:12:54Z")

</div>

**EDIT: [Replied in the first thread - continue it here]**

The code I included does what I want, it’s just after I added the `system.tag.getConfiguration` call, it got noticeably slower (again, it takes about a second so its not a deal at all). I mainly want to understand the best way to get custom properties for a tag through scripting.

Here is a highly redacted version of the tag structure I’m working with:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/2/32c96d1dae5ce3c27eb3cd608b93203ed976cd4f.png)

The blue line is what the root tag path references (18 UDTs with \< 20 tags each). Each of the UDT instances by the yellow dashes have a folder called Overview within them and in that folder, there are certain tags that will be displayed on an overview screen, like so:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0da7b004c885ddaec29ddc921efd9af52e7b5f15.png)

which translates to this on the view:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e29a5db9d0c6f8d97c306cf12585350755395ce3.png)

I set it up this way so that I can have other tags that won’t be displayed in the Overview screen, and if I want to add other data points to the Overview, I simply add a tag to the folder for that UDT and it appears there dynamically. In this case, the UDT shown above has a `Speed`, `Torque`, and `Vacuum` tag and each of those has a `Units` custom property coming from the UDT definition (`FPM`, `%`, `" w.c.l`, respectively).

I tried filtering on certain tags, but there is more than one UDT definition I’d be filtering on which have different tags (also, some UDTs have matching tags but they’re outside of the `Overview` folder), so I couldn’t get a consistent and scalable result…

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 29, 2022, 8:40pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579/4 "2022-08-29T20:40:51Z")

</div>

> [@YF129701](#):
>
> I mainly want to understand the best way to get custom properties for a tag through scripting.

Tag event script, project script, script transform, doesn't really matter. There are only two ways to access tag properties.

1. Use `system.tag.read*` with dot notation as shown by @paul-griffith
2. Use `system.tag.getConfiguration()` and access the property from the returned List of Dictionaries.

A small caveat is that `system.tag.getConfiguration()` currently only returns properties with non-default values, so if you're trying to access a property with a default value, then you're stuck with `system.tag.read*`. I'm not sure where custom UDT properties fall into that.

The reason that adding `system.tag.getConfiguration()` slows down the script, is because you are calling it multiple times. (~180+ times according to the information you've provided). You will see a similar slow down if you use `system.tag.read*`.

I am not at a place where I can work through a loop that would be faster. If that is something you would like to see then, I can possibly work on it later. I would think you're going to need some type of recursion though.

---

<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:** [August 29, 2022, 8:53pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579/5 "2022-08-29T20:53:13Z")

</div>

I don’t know offhand if it does, but does reading `UDT/Folder.jsonValues` give you access to subnodes?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [August 29, 2022, 9:03pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-custom-properties-through-scripting/63579/6 "2022-08-29T21:03:54Z")

</div>

It seems like it does. I’m refactoring my script to read the entire tag structure once and then I’ll report back. Also, the original custom property was to keep track of the tag units, but I found that I can use the `engUnit` property instead (duh).
