filterTag - Tag Browse Tree

Hi, all.
I'm trying to do a tag filter in my Tag Browse Tree with Historical Tags. I'm using the filterTag function. I saw many forum entries but I can't resolve this. Even if I only script return False, the Tag Browse Tree shows me all the tags. I can't print for debug, neither.
Is there something too wrong that I'm not seeing? How to use thefilterTag function correctly?
Thanks to all.

Felipe

I don't know how your code is structured, or what you are using to filter, but any property should work. Take this sample tag browser for example:
image

If I filter on tag name using the text field, here is the result when I type "Test" into the box:
image

This is the code used in the filterTag extension function:

def filterTag(self, tag):
	if self.parent.getComponent('Text Field').text in tag.name:
		return True
	else:
		return False

What you are probably missing is the refresh() method. To get the above effect, I have the following script on my text field's keyReleased event handler:

event.source.parent.getComponent('Tag Browse Tree').refresh()

This refreshes the data in the tag browse tree every time a character is added to the text field

1 Like

That suggests you aren't indenting correctly under the def ... supplied by Ignition.

Justin, thanks for so complete answer!
Yeah, by one side, I had a wrong configuration in the Tag Browse Tree that I already fixed it.
And now, by the other side, I see that I have more subdirectories than you in your example.
I mean: I have within default, plc and UPS folders, for example. And within plc other subdirectories ordered by sector.
Is this possible to be filtered?
I am so sorry for my horrible english.

I see. In that case modify your filter to always include folders. Modifying the above example will illustrate one possible approach that would work:

def filterTag(self, tag):
	if str(tag.objectType) == 'Folder' or self.parent.getComponent('Text Field').text in tag.name:
		return True
	else:
		return False
1 Like

thank you, this code saved me :sweat_smile:

1 Like