Hi, i am using tag tree browser in my project in different modules
In future if customer adding a folder called system tags that i want to hide, but instead of going to every tag tree browser and write script in filter tag
i want to write common script that has to hide folder in all tag tree browser in different modules
Is this possible to do?
def filterTag(self, tag):
"""
Called for each tag loaded into tag browse tree. Return false to hide this
tag from the tree.
Arguments:
self: A reference to the component that is invoking this function.
tag: The tag itself.
"""
if tag.name == 'Parameters': # Hide "Parameters" for UDTs tags
return False # Hide tag
elif tag.name == 'Node Control':
return False # Hide tag
elif tag.name == 'Node Info':
return False # Hide tag
elif tag.name == 'Device Info':
return False # Hide tag
elif tag.name == 'SystemTags':
return False # Hide tag
elif tag.name == 'Energy' and self.parent.getComponent('DropDown_TreePath').selectedIndex == 1 :
return False
else:
return True # visible tag
i want to use this script in common place for all tag tree browser
Use a project script module. Define your filtering function there. Make all of your tag tree browsers filterTag() methods a one-line call to the project script function.
No. What I described just puts the code in one place for you to maintain. At it's simplest, it doesn't cache any data. Though caching is possible with a top-level variable (dictionary, typically) in such a project script module.
@pturmel i tired but i don’t know how to call the ( Make all of your tag tree browsers filterTag() methods a one-line call to the project script function.)
please give one example how to call it
i will attach code also
def filter(tag1,tag2):
if tag.name == tag1: # Hide "Parameters" for UDTs tags
return False # Hide tag
elif tag.name == tag2:
return False # Hide tag
this is the code i have written in project library and image also i have attached
Your project script function should be exactly like the original component method, accepting self and tag as parameters. Then the new component method will be one line:
You are missing the return in your screenshot. The filterTag component method must return the filtering instructions. So your one-liner must return the result from the project script.
This project script is only callable from the filtering context. It is meaningless to call from a button or any other outside context.
one question , actually i want filter tag folder selection is to be done by operator in client
i have a module in that they can mention the folder which they don’t want to see
is it possible to pass filter tag path dynamically to project library script?
Then use that string in the function to condition your filtering. You would bind the string property to a dropdown box or some similar UI component to select your filter condition.
As you have set it up, myFilterFolder isn’t a variable by itself in the component method. Only self and tag exist there. You can either reference it from self in the component method to pass to the script function, or you can leave off the third argument (in both places) and just use self.myFilterFunction inside the project script.
This is basic python object and function behavior, not anything specific to Ignition. You should consider a python tutorial to fill in the gaps.