Tag Browse Tree Filtering

This tool has been around for a while, but I cannot seem to find useful help/ examples of how to filter out tag directories at varying levels of the tree. I know I will probably need to be using filterTag extention function but the manual doesn’t go in to how to use this function. And , obviously my trial and error attempts to make it work for me have been futile up to this point.

I’ve “filtered” the top level of the tree, but cant figure out how to filter sub directories, and make it open the window with those non filtered sub directories displayed in the tree. Am I missing it in the manual somewhere? Could I please see a sample?

        //This filters the top directory

	print tag.name    //prints: MainDevice
	if tag.name == "MainDevice":
		print "true"
		return True
		return False


The filterTag will have to return true for every tag you want to display. The difficulty is knowing the tag names dynamically and not hard coding the tags to return. If you know them all, you could do the same thing you are doing for the mainDevice and just run several if statements. You need to do checks for each part of the Tag or else it won’t show in the tree. For example,

#'MainDevice/Directory/TagName' if tag.name =="MainDevice: return True elif tag.name == 'Directory': return True elif tag.name == "TagName": return True
Also in my experience the flterTag is run every time a folder is opened, it doesn’t check all the tags at the beginning.

You could also refine Nick’s example a little bit with some Python string manipulation:

#'MainDevice/Directory/TagName' if tag.name =="MainDevice: return True elif tag.name == 'Directory': return True elif tag.name == "TagName": return True


if tag.name in 'MainDevice/Directory/TagName'.split('/'): return True

[quote=“PGriffith”]You could … becomes:

if tag.name in 'MainDevice/Directory/TagName'.split('/'): return True[/quote]Have a care for speed. This method is called for every node. Consider doing such a split in a script module at the top level, effectively yielding a constant:[code]# Script module project.tagtree

tagparts = “”“MainDevice
Lines”"".split("\n")[/code]Then your event script becomes just:return tag.name in project.tagtree.tagpartsBlistering fast in comparison