setTag and getTag?

Im wondering if you can have more than one tag per node (like python dictionary)?
Are tags inherited by child nodes?
Are they keys only strings?
And do (multiple) tags work with the chicken exporter properly?

I suggest trying experiments to answer these questions for yourself. Questions like these are very easy to discover answers for. :slight_smile:

David

Sometimes you dont get error but in fact it doesnt work, although it seems it does

OK, i think i got it all.
I dont understand pythonTag though. It says it can store any python object as value. I dont really understand that. Can you give any example on how that could be used in practice?

nodePath.setPythonTag('foo', 1)
nodePath.setPythonTag('bar', { 'a' : 2, 'c' : 3 })
nodePath.setPythonTag('baz', nodePath)

yes, but how could that be used, having a nodepath assigned to another nodepath’s tag?

BTW, I tried exporting a tag with Blender chicken exporter. It seems to export an empty string.
This is how it is in the file:

<Tag> keystring { valuestring }

but

print node.getTag('keystring')

returns “”.

It’s usually used to work around the problem with subclassing from NodePath; see Subclassing. But it can be used in general anytime you want to piggyback arbitrary Python data in the scene graph. If you don’t have any reason to do that, then don’t worry about it.

You probably have the wrong node. For instance, maybe you have a parent node. Try:

print node.find('**/=keystring').getTag('keystring')

Or, less likely, maybe you have a child node, in which case:

print node.getNetTag('keystring')

Or, just look at the whole thing:

model.ls()

David

Oh, it found it. Thats strange, theres only 1 geom.
Its the monkey model from Blender.

monkey = loader.loadModel('suzanne')
monkey.reparentTo(render)

print monkey.getTag('keystring')

i wonder why it doesnt find it just like this.

Because when you call loader.loadModel(), what you get back is a tree of nodes, with a ModelRoot on the top. The nodes represent the structure of the model as read from the egg file, and the ModelRoot is just a uniform handle to the top of the structure.

But the tags are stored deep within the structure, not on the ModelRoot. So if you want a particular tag, you have to find the node it’s on.

Even if there’s only one Geom in the model, there is still a ModelRoot on top. This makes things consistent.

David

Oh, ok.
Ill read more on the “find()” syntax then. I seem to have forgotten that.

When i started writing shoot them up sample/demo, in last few hours when i was working on it, i started using panda scenegraph to hold links to my objects, so for example i have Bullet python class, and object of that class creates timers( panda task ), when that task expires (bullet flies some distance then destroys itself), this object is attached to panda node which was created in same class.
When i want to destroy bullet node, i just remove or clear python tag that tied object to node, and delete node from scenegraph, and after that, bullet object is not being used anywhere so it goes to garbage collector…

Is that abusing of panda scenegraph? I find it very nice to work like that, its very easy to access parents and children python objects.

Nothing at all wrong with that.

Thanks for tip, i was afraid that its wrong (in a too good to be true way :slight_smile:)