I can filter the tag path using the tagBrowserStartPath attribute, but I would like to filter tags by name. Ideally, I could enter *FIT* in a field, and only tags starting with "FIT" would appear in the Tag Browse Tree.
Are you looking for something along these lines? It's not perfect but I think it works for what you are asking or at least is a starting place for you to take the code further. I had some issues with filtering where tags had the same name but with additional characters. so the filtering isn't perfect. #stillLearning
I put the following on a change script for the text field.
import os
import system
import re # Import regex module
def print_historian_tags():
provider_path = "Name of Tag Histornian"
# Get the filter text and set to empty string if the text field is empty
filter_text = getattr(self.props, "text", "").strip().lower()
if not filter_text: # If filter_text is empty or None
# Set tagBrowserStartPath to empty string when the filter is empty
self.getSibling("PowerChart").props.config.tagBrowserStartPath = ""
else:
def browse_tags(path):
results = system.tag.browseHistoricalTags(path=path)
for tag in results.getResults():
if tag.hasChildren():
browse_tags(tag.path)
else:
tag_path = str(tag.path).lower()
# Using regular expression to match more precisely (whole word match)
if tag_path.startswith(provider_path.lower()) and re.search(r'\b' + re.escape(filter_text) + r'\b', tag_path):
parent_folder_path = os.path.dirname(str(tag.path))
system.perspective.print("Parent folder path: " + parent_folder_path)
# Setting the value for tagBrowserStartPath
self.getSibling("PowerChart").props.config.tagBrowserStartPath = parent_folder_path
browse_tags(provider_path)
print_historian_tags()