What am I doing wrong?

I’m new to panda3d(i’ve gone through the tutorials, but thats about it), and I am trying to load one of my own models into the game(not realy a game, it’s only five lines of code so far). My model is a simple plant model that is in .x format, and here is the code to make the model show up.

import direct.directbase.DirectStart 

#Load the first environment model 
plant = loader.loadModel("models/plant.x") 
plant.reparentTo(render) 
plant.setScale(0.25,0.25,0.25) 
plant.setPos(-8,42,0) 

run()

But when I run it from the command prompt I get an error saying “AttributeError: ‘NoneType’ object has no attribute ‘reparentTo’”, does anyone know what I’m doing wrong?

Thanks in advance

Look at the error message. It bet it gives you the line-number of this line:

plant.reparentTo(render)

The error message says that “NoneType” has no attribute “reparentTo”. So obviously the varibals “plant” has type “NoneType”. And there is only one object that has type “NoneType”: the object “None” itself. This mean that at this points of your script the variable “plant” has the value “None”.

How can this be? The variable plant gets assigned one line above:

plant = loader.loadModel("models/plant.x")

So obviously the method “loader.loadModel( )” has returned “None”, and not an instance of NodePath, as you might have expected.

There are several ways how a method could deal with internal errors. One would be to raise an error and stop execution. “loadModel” chooses another way - if an error occurs then it returns an error value: “None”. By the way: It is strongly encouraged to check return values with such methods.

There could be several reasons why “loadModel” fails. The most likely is that the path is wrong. Maybe you check what your model search path is, and if there is a file “models/plant.x”.

ennox

I figured it out. It wasn’t a scripting error at all. I’m using conv3ds to convert from .3ds format to .x format, and it does convert them, but to binary .x format instead of a text format. And Panda3d says something about not being able to read binary .x format. All I had to do was make conv3ds convert it to a text format instead. But thanks for the help anyway.