Make a .blend file using python

Hello,

I am currently in the need to create a python program that outputs a blender file. The program needs to output multiple 3d models to a .blend file. If someone could explain something “simple”, such as writing two cubes to a file, I would be able to figure it out from there. Any help is greatly appreciated.

that isn’t a trivial task, you should rather use a common format like OBJ for interchange. What’s the whole process you wanna accomplish?

I am trying to program a game with a randomly generated map. I have tried doing it based on voxels, but with each voxel being an object on the screen it tends to lag more than I like. So my plan was to compile the voxel data into “chunk” objects and bring them into the blender game engine with libLoad so the face count remains the same but the object count goes down, as well as many computing algorithms.

Just use SaveAs.

bpy.ops.wm.save_as_mainfile(filepath=render_filename, check_existing=False, copy=True)

This will save the current state of the Blender datablocks, who have more than 0 users, to a file.