I managed to get it working another way using readAll():
list1 = 
FiltTags = 
tags = system.tag.browseTagsSimple(folderpath, “ASC”)
for tag in tags:
if (filt in tag.name) and (not tag.isFolder()):
return sum([x.value for x in system.tag.readAll([y.fullPath for y in FiltTags])])
I’m not seeing any reduction in CPU usage however (probably because I’m still filtering the tags one by one).
You could also save CPU cycles by caching your tag list in a script module global dictionary. Or if you are kicking it off from an expression tag, you could stash the list of tags in the
state variable of the objectScript() expression function. Part of Simulation Aids.
I bet it’s the browsetags that is eating up your CPU. Suppose you write another script to cache your tagpaths in a dataset tag, and set that script to run once per day (at midnight or something). And then for the expression tag, just do your readall on the cached dataset.
That’s a great idea. I shall give that a try tomorrow. In the real world it may not be too much of a problem, but this is just for a development / test project that I’m running inside a very resource limited VM. Thanks for your suggestion.
If you want to try objectScript, place this in a shared script (tagops, f.e.):
# Pass state and operation=something, the rest goes to browseTags()
def folderOp(state, *args, **kw):
# Perform a summation on the list of values by default
operation = kw.pop('condition', system.math.sum)
if not 'paths' in state:
state.paths = [x.fullPath for x in system.tag.browseTags(*args, **kw) if not (x.isFolder() or x.isUDT())]
return operation([x.value for x in system.tag.readAll(state.paths)])
Then in your expression tag, do something like this:
objectScript('shared.tagops.folderOp(state, "[provider]some/path/to/folder", "*_AMPS")')
Note the careful use of single- and double-quotes.