How to save (..and load..) blender objects with python

I’m running these elaborate codes to create objects. At some point, I run the following line of code: bpy.data.objects.new() that creates an object based on a mesh. Then similar lines add materials, then vertex groups, etc. This “object” that has been created, eventually gets linked into a scene, and displayed. What I’d like to do, eventually, is instead of creating all my objects from scratch every time, simply import them (having saved them previously). You can see why I put this in “Basics”. For example, I might want to change one particular part of the scene, one of the objects of the scene. That object will have to be re-generated, or re-calculated, but all the others… will remain the same. So the question is, how to save all those other objects? (…and then load them back in again…) (all with python) What file format should I use? I’m reading about .obj files and .blend files. in my understanding, a .blend file is a whole big whopping thing that includes the workspace itself. Totally not what I want. But people are saying that that’s the only way of saving all the information. Still researching. Intuitively .obj is what I want, but I don’t know enough about what it actually is, and I’ve seen places where people explicitly recommend against it, in favour of .blend . You see my confusion.

The formats are somekind all over the place ?

  • bpy.ops.wm.FORMAT_ex/import for export/import alembic, collada
  • bpy.ops.export_mesh seems to be have only ply and stl. bpy.ops.export/import_scene has fbx, gltf, obj…
  • or even bpy.ops.wm.link/save_as to use a blend file…

Thank’s for the info! This thing looks like a rabbit-hole to me… I’ll figure it out eventually!

Anything but a .blend file would be considered an ‘exchange’ format for working across different pieces of software. If the files only need to work with Blender, use .blend.

Obj is an arcane glorified txt file. Appropriate modern alternatives would be abc or usd.

A blend file is only as big as what’s in it and any UI arrangements stored would be minuscule. They can also apply compression when written.

…Fascinating… …you are motivating me to learn more about blend files… :slight_smile: