# Export/Extract tag path for OPC tags based on scanclass

**URL:** <https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [October 26, 2020, 8:43pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034 "2020-10-26T20:43:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [October 26, 2020, 8:43pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/1 "2020-10-26T20:43:08Z")

</div>

Hi All  
I’m trying to export the tagpaths for multiple tags based on a particular scan class on my Ignition project. I tried to load the configuration file (config.idb) in MySQL lite and get it from there but no luck. I also tried to use scripting: system.tag.browseTags() to get the list of tags and sort according to the scan class but no luck there either.

This is the code snippet that I ran as a project script:

def tagpath():  
tags = system.tag.browseTags(parentPath="", recursive=True)

```
for tag in tags:
	tagScanclass = tag.name + ".Scanclass"
	tag2 = system.tag.read(tagScanclass)
	if tag2.value == 'my_scanclass_name':	
		print tag.path + "," + tag2.value

```

The ultimate aim is to export the OPC item path with the node id, device and path but if I can get at least the tagpath that would be great.  
If anyone could think of a better way of doing it please leave a comment. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![aharris](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@aharris](https://forum.inductiveautomation.com/u/aharris)\
**Post date:** [January 28, 2021, 3:29pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/2 "2021-01-28T15:29:59Z")

</div>

I need to do a similar thing here. Did you figure it out or does someone know how to accomplish this?

I can set the scan class through scripting but can’t figure out how to get the scan class through scripting to filter on.

I’m trying to change the the scan class through scripting in a particular folder. The original scan class is Default so it doesn’t show up in the xml export since only non default settings show up there. It does show in the csv export but I can’t use that because some of the tags have alarm configuration which is not included in the csv. I tried anyway hoping it would leave those settings alone but it stomped on all the alarm configurations and they disappeared.

Thanks!

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [January 28, 2021, 5:25pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/3 "2021-01-28T17:25:38Z")

</div>

I was able to export the tag paths from the config.idb file later on. In my case, I used a custom scan class so it might not work for you but give this a shot,

- Get the config.idb from the computer where the gateway is installed

- Use SQLite, an application for viewing the idb file

- Run this query (might need some modification)

select t.name as tag,p.strval as OPC\_Path from sqltag t  
inner join sqltagProp p on t.sqltag\_id=p.tagid and p.name=‘OPCItemPath’  
where t.scanclass=‘_name of scan class_’

- After you get the list maybe you can set the scan class through scripting since you already have the filtered tags that you need.

Hope this helps. Out of curiosity, what function did you use in your script to set the scan class?

---

<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:** [January 28, 2021, 5:45pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/4 "2021-01-28T17:45:01Z")

</div>

The following code works?

```auto
def tagpath():
	tags = system.tag.browseTags(parentPath="MyTagFolder", recursive=True)
	tagList = []
	for tag in tags:
		tpaths = ["[default]"+tag.path+".ScanClass","[default]"+tag.path+".OPCItemPath"]
		tinfo = system.tag.readAll(tpaths)
		tagList.append([tag.path,tinfo[0].value,tinfo[1].value])
	return tagList
ret = tagpath()
print ret

```

---

<div class="post-metadata">

**Author:** ![aharris](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@aharris](https://forum.inductiveautomation.com/u/aharris)\
**Post date:** [January 28, 2021, 9:12pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/5 "2021-01-28T21:12:56Z")

</div>

Thanks sathianandan! I had no idea you could look at and modify the config.idb with sql. I will try this. As for how I modified the scan class below is my script. I filtered on tag type but cannot figure out out to filter on scan class.

```
folder = "PLC/SP" + str(sp) + "_INT"
tags = system.tag.browseTags(parentPath=folder,recursive=True)
for tag in tags:
	if str(tag.type) == "OPC":
		tagPath = tag.path
		print tagPath
		system.tag.editTag(tagPath=tagPath,attributes={"ScanClass":"Default 2"})
```

---

<div class="post-metadata">

**Author:** ![aharris](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@aharris](https://forum.inductiveautomation.com/u/aharris)\
**Post date:** [January 28, 2021, 9:14pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/6 "2021-01-28T21:14:46Z")

</div>

Thanks for posting this MMaynard. Looks like a different way to go about changing the scan class from how I did it (just posted script). Do you know how to filter by scan class? In other words add an if statement to your script that evaluates for a specific scan class and then changes is using your script.

---

<div class="post-metadata">

**Author:** ![aharris](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@aharris](https://forum.inductiveautomation.com/u/aharris)\
**Post date:** [January 28, 2021, 9:21pm UTC](https://forum.inductiveautomation.com/t/export-extract-tag-path-for-opc-tags-based-on-scanclass/40034/7 "2021-01-28T21:21:32Z")

</div>

Now I see MMaynard. Your script does get the scan class. I think this will work. Thanks again!
