Perspective Tag Browse Tree - Show only tags with alarms

I'm trying to use the filterBrowseNode extension function to display only tags with alarms, but it's proving difficult...

If I use this below, I only get tags with alarms in the root folder:

	system.perspective.print('{}: {} attr: {}'.format(node.name, node.getDataType(), node.getAttributes()))
	
	if 'alarm' in str(node.getAttributes()):
		return True
	else:
		return False

And the print statements show:

10:20:46.659 [Browser Thread: 62914] INFO Perspective.Designer.Workspace - 5s Clock Pulse: Boolean attr: [NodeAttribute[scripting]]
10:20:46.660 [Browser Thread: 62914] INFO Perspective.Designer.Workspace - Area Filter: DataSet attr: []
10:20:46.660 [Browser Thread: 62914] INFO Perspective.Designer.Workspace - SMS Notification: String attr: []
10:20:46.661 [Browser Thread: 62914] INFO Perspective.Designer.Workspace - Take Thread Dump: Boolean attr: [NodeAttribute[scripting]]
10:20:46.661 [Browser Thread: 62914] INFO Perspective.Designer.Workspace - Test SMS Alarm 2: Boolean attr: [NodeAttribute[scripting], NodeAttribute[alarm]]

for this test folder structure:
image

Note that SMS Notification/Test SMS Alarm is completely missing

I've tried adding into the if condition node.getDataType() == 'Folder' and also converting to str before comparing, but folders don't appear to be Nodes that are ever returned, so this doesn't work to include folders :confused:

The SMS Notification folder is in your printout, so it certainly was handed to your filter. It just lied about its datatype. You might have to do some more introspection to figure out how to detect them.

Oops, you're right. That's annoying still though... I can't use hasChildren() because standard tags have children (their properties) :confused: I'll keep digging... it's certainly not easy

Got it, getObjectType() returns 'Folder'

1 Like

Try using node.getType(), not just node.getDataType().

So the resulting filter is:

if 'alarm' in str(node.getAttributes()) or str(node.getObjectType()) in ('UdtInstance', 'Folder'):
	return True
else:
	return False

You might need another case for UDT instances.

1 Like

I got excited, haha. Edited my reply to add UdtInstance. What I really want to do is to not show folders/udt instances that don't have alarm tags in them... but I don't think that's possible since the filter is run on each node

Cache the folder results in a project library script top-level variable and reference that in your filter.

1 Like

Ha, that's clever, i'll do that :slight_smile: thanks!