Search code examples
pythonopengl3dblender

Saving .3ds or .obj files using Blender API


I would like to create 3ds or .obj files with python. For example I want to create a cube with python programming and I want to save it in a file like "cube.obj"; how can I do that?

Solutions that I have tried:

1) Blender API for python

  • I can create 3d models but I cannnot export them as a file. Or if I want to export them then I need to open blender and paste my code in text editor.

2) OpenGl for python - I can create models but I cannot save the model as a file.


Solution

  • If you want to export as OBJ.

    import bpy    
    bpy.ops.export_scene.obj(filepath="", use_selection=True)
    

    filepath is where you want to export the model

    use_selection is if you want to export the whole scene or just the selected part

    There are a lot more you can do with this function via arguments you can read about it here