DirectFrame geom out of a NodePath?

It’s 3am and it’s probably not the best time to try find something in an API, but I’ve been trying unsuccessfully to set the geom_scale of a DirectFrame object, after creation.

The problem lies in the fact that I have a handle to its NodePath rather than the actual DirectFrame. Is there a way to get hold of it? I.e. if I have the following code:

aParent =  NodePath("parent")
DirectFrame(parent=aParent, geom=someGeom)

How do I get a handle to the geom starting from “aParent”?


Ok, I made a more complete example and found a workaround, but there must be a better way, isn’t there?

from direct.directbase.DirectStart import *
from direct.gui.DirectGui import *
from pandac.PandaModules import *

aCardMaker = CardMaker("Frame")
aCard = render.attachNewNode(aCardMaker.generate())

aParent = base.aspect2d.attachNewNode("aParent")
aFrame = DirectFrame(parent=aParent, geom=aCard, geom_scale=(0.1, 0.0, 0.1), relief=None)

## so, what have we got so far?
for child in aParent.getChildren():
    if(child.getName() == "theFrame"):
        print(type(child))          ## this returns <type 'libpanda.NodePath'>
        print(type(aFrame))         ## this returns <class 'direct.gui.DirectFrame.DirectFrame'>
        print(type(child.node()))   ## this returns <type 'libpanda.PGItem'>
        print(type(aFrame.node()))  ## this returns <type 'libpanda.PGItem'>
        print((child == aFrame))    ## this returns True
## from the previous printouts, if I don't have a direct reference
## to "aFrame", i.e. because I'm in a different part of the program,
## I wouldn't be able to access the DirectFrame object. All I would
## normally be able to access are the methods of NodePath and PGItem.

## The only solution so far: store the DirectFrame object on the NodePath as a python tag...
for child in aParent.getChildren():
    if(child.getName() == "theFrame"):
        child.setPythonTag("theDirectFrame", aFrame)

## ... to then retrieve it elsewhere in the application
for child in aParent.getChildren():
    if(child.getName() == "theFrame"):
        theFrame = child.getPythonTag("theDirectFrame")
        theFrame.setProp("geom_scale", (0.1, 0.0, 0.4))


I suspect there’s a very easy solution to this but I haven’t been able to find it! :blush:


Usually, the best solution to this sort of thing is not to lose track of the original DirectFrame pointer in the first place. If you have to pull the DirectFrame out of the scene graph, all you’re going to get is a plain NodePath, and you need to use some kind of trick like setPythonTag() to map that NodePath back to the DirectFrame object.