Load scene data from py file?

I am trying to load a scene into my level editor from a python file. I have loaded the path of the model, and transformations into a list. How do I load and transform the models when I only have strings?


"nameOfModel" = loader.loadModel("pathToModel")

Another option I have thought of is just directly importing the python module containing the scene after selecting it from the tkFileDialog, but I run into the same string issue. :frowning:

I’m not sure if this is the most efficient or best way to do this but you could always use:

exec('nameOfModel = loader.loadModel("pathToModel")')

Or if you have the string name as a variable:

exec(nameOfModel + '= loader.loadModel("pathToModel")')

There might be a better way to do it.

:open_mouth: I can’t believe that actually worked! I’m definitely scribbling that command down in my notebook-

Thanks, Kijaro :smiley:

If you want it inside a class object, it is slightly better to do:


and then to manipulate the model:


because with the first method you have to use an exec statement every time you want to get the model… (although Azraiyl’s way is probably the best)

Or you store all your models in a dictionary.

models = {}
models["nameOfModel"] = loader.loadModel("pathToModel")

modify your models is simple then e.g. hide one model:


I agree. :laughing:

exec() is also a command you should never use with user input. As you saw, if that happened then a user could execute whatever command he wants inside your script. Exec() does have it’s usefulness, especially for testing purposes where you know you’ll go back and clean up your code or code no one but you is going to be touching, etc. I’d stick with Azraiyl’s idea in this case. :slight_smile:

I just finished implementing Azraiyl’s method and it works out real nicely- thanks for the help everyone! :smiley: