NodePath.find issues...

To keep this short and simple…

Just when I thought I had this thing all figured out, I’m having a few issues with the NodePath class.

(First of all, for any who might wonder this, the manual often says “nodePath” instead of “NodePath”, which is a problem :stuck_out_tongue: )

When I used the NodePath.find() method as shown just below, I keep getting the following error:

Every example that I can find in the manual uses hardcoded strings, rather than variable insertion. “listedItem[11]” IS a string. It has been freshly derived from a string. I just can’t seem to make use of the documentation described here: http://panda3d.org/manual/index.php/Searching_the_Scene_Graph

Any ideas? I’m sure it’s simple, but I’m stumped.

Yes. The clue is your first confusion:

The manual should do a better job of clarifying the distinction between “nodePath” and “NodePath”. See, “NodePath” is a class name. The symbol “nodePath” is not a class name, and might therefore be any ordinary variable, presumably an instance of the NodePath class.

So when the manual says:

nodePath.find('**/foo')

it means to create an instance of a NodePath class and store it in a variable called nodePath (or the name of your choosing). Then you can call find() on that instance. And find() does accept a string, by the way, but when you try to call find() on a class, instead of an instance, Python gets mad and prints a confusing error message about the wrong parameters passed to the function.

David

Your code looks like its calling .find from the NodePath class instead of a NodePath instance. Try render.find() instead, or substitute render with another nodepath if you know where to start the search from.

thank you both for your replies. That’s precisely the silly mistake I knew I had to be making.

This raises a related question, though…

The manual says that this find() function will return an empty NodePath if it can’t find a match. …How do I represent that in code? In other words, how do I test to see if nodePath is empty? I can’t seem to find any resource to read about that kind of assertion.

thanks

oops, nevermind. i’m a dork. i already know how to test that :stuck_out_tongue: “nodePath.isEmpty()”

( i had been expecting it to be “None”, and that’s quite different from an emtpy NodePath)

Tonightslastsong, please note that the naming of the NodePath instance in the page you mentionned has been changed to myNodePath to make it consistent with the page named “Schene graph manipulation” earlier in that section.

This should prevent the possible confusion.

Cheers,

Christian

Very nice-- thank you. Even though I understand very well the concepts in play, I completely misunderstood the text!