wm bpy Operator: Appending with Python in BGE

Hey there,

I found several posts regarding appending with python. I’ve given my best shot to append a blend or it’s objects/Groups to the current blend via python. Nothing I tried worked. I’m getting the “Look in the console for now” error. The console says that the file to append is not a library, no matter what blend i tried with.
I’m on Mac OS 10.8 btw, using Blender 2.63.

My goal is to add cars from external blends to the racing environment by an empty object. The best would be to append it’s whole group or the entire blend file.

EDIT: This is the key:

Code:

import bge
bge.logic.LibLoad("//cars/car1/car1.blend", “Scene”, load_actions=True, verbose=True)

This imports all scenes to the blend. Well, that was easy.

/EDIT

Things I tried out:

import bpy
bpy.ops.wm.link_append(filepath="//cars/car1/car1.blend", directory="/Users/marv/Desktop/RV BLender/cars/car1", filename="car1.blend")

or


...
bpy.ops.wm.link_append(filepath="//cars/car1/car1.blend/Object/Body_car", directory="/Users/marv/Desktop/RV BLender/cars/car1.blend/Object", filename="Body_car")

and some other varieties.

I.e. my questions are:
How to i append…
-a group
-an object
-an entire blend file
… to my current project in BGE?

I’m really looking forward to your help.

-Marv

You actually can’t using bpy. When you press P-Key in the 3D window bpy is still available because the GUI still exists. BPY does not exist in the Blender Game Engine at runtime. So your whole scheme will fall apart once you publish your game. If your game code will always be run from within Blender Internal it might work.

The BGE uses another concept called Libraries do some research on that term.

That was quick, thanks for your reply.
Do I linked the car to the blend. I’d have to use bpy again i guess…
I can’t quite figure out how to do that without bpy.

I got it!

import bge
bge.logic.LibLoad("//cars/car1/car1.blend", "Scene", load_actions=True, verbose=True)

This imports all scenes to the blend. Well, that was easy.