Trouble finding tags

I’m attempting to find a set of tags that I’ve applied to a piece of geometry in Blender and exported via YABEE.

[edit]

All right, I’ve figured out why “getNetTag” wasn’t turning up my tag, I believe. It turns out that I wasn’t sufficiently thinking about what the method description said when I read it: the “*netTag” methods search up the node tree, not down.

So, my question has changed: is there any way, short of iterating over all children, of finding a node at or below a given node that has a specific tag – or better yet, all nodes that do?

The remainder of my original post should be below.

[/edit]

The resultant egg file does appear to have the tags as desired:

# ...
  <Group> water {
    <Tag> "u speed" { 0.30000001192092896 }
    <Tag> "v speed" { 0.019999999552965164 }
    <Tag> "u scale" { 20.0 }
    <Tag> "v scale" { 12.0 }
    <Tag> "rotation speed" { 10.199999809265137 }
# ...

Calling “ls()” on the loaded geometry produces the following output, I believe:

ModelRoot water_surface.egg [depth file] T:(pos 0 0 -1.02286) S:(CullBinAttrib LightAttrib)
PandaNode 
GeomNode water (1 geoms: S:(MaterialAttrib TextureAttrib)) [rotation speed u scale u speed v scale v speed]

Note the section in square brackets on the last line.

So it looks as though the tags are present… and yet all calls to “getTag”, “getNetTag” and “findNetTag” have failed to reach them, it seems: the “get” methods return empty strings while printing the result of the “find” method produces “not found”. :confused:

So, where am I going wrong? Are there perhaps formatting restrictions on tag keys, such as whitespace being disallowed?

# -*- coding: utf_8 -*-
from panda3d.core import *
import direct.directbase.DirectStart

m = loader.loadModel('tags')

# --- First way ---

for geom in m.findAllMatches('**/+GeomNode'):
    if geom.hasTag('my tag'):
        print geom

# --- Second way ---

def find_tags_iter(np, tag, result):
    for child in np.getChildren():
        if child.hasTag(tag):
            result.append(child)
        find_tags_iter(child, tag, result)
nps = []
find_tags_iter(m, 'my tag', nps)
print nps

run()

Second way is more multipurpose.

Wouldn’t it be faster to use nodepath.findAllMatches("**/=tagname")?

Yeah, you right, I completely forgot about this feature

And I didn’t know about it!

Thank you both. :slight_smile:

In the end, I find that I have a number of tags to search for, so for now, at least, I’m going with the expedient of searching through the children of a given node for nodes that have any of my tags and applying them as called for. It seems to work, although it does incur a little ugliness: while my GeomNodes seem to be visible when printing out the resultant NodePathCollection, and seem to be vaid children (an appropriate call to “getChild” on the relevant NodePath seems to return a valid result), for some reason they don’t appear when iterating through the NodePathCollection. As a result, I ended up iterating through it, then for each node iterating over its children and checking for any not already in the collection; any such are added to the collection.