I have written an elaborate python code that creates complex objects from scratch. [Well, technically I use the numpy functions
load here and there to fetch integer and float array data I generated previously.] My code generates, say, a hundred or so complex objects. Now, as part of the artistic methodology I propose, I want people to be able to look at the objects the code has generated, and see if they like them. If there is something wrong, say one of them is a soccer ball that is just too small, I want them to be able to go into the code and edit the value of the radius of the ball, to make it bigger. [..I realize that there is probably some part of the api, or an addon, that will allow me to allow them to do this super efficiently, but that isn't what this question is about. Maybe I'll make a separate question about that later..]
Now, having changed that value, (..they might have changed multiple values of different objects..) I want them to be able to run the code again, to see what the effect is of the new value(s). Of course, if there wasn't anything wrong with any of the other hundred complex objects, I don't want the code to re-create them all over again from scratch. So I would like the code to have saved them all the first time around so that the next time it is called, all the parts that haven't been changed will just get re-loaded. I would have a script to identify which ones had been changed, and which not.
Now, to create an object, you need arrays for vertices, indices, where the loop of a given surface starts, and how many vertices define it. I know how to save -that- information (which is used to create the object mesh) as a set of arrays, then load it back in. If there isn't any way of saving objects, I'll just do that. What I'm wondering is whether I can go the extra step to saving the object.
To be clear about what I mean by
object, it's what is produced by the following python line:
bpy.data.objects.new(). That gets followed by things like
object.data.materials.append(materials[material_number]) to give it a material, and
body_of_object = object.vertex_groups.new( name = material_name ) and
body_of_object.add( vertex_group, wanted_weight, 'REPLACE' ) to define vertex groups.
This "object" that has been created, eventually gets linked into a scene, and displayed.
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.
Note -> This has been edited. I would not be surprised if there is need for more edits in the future..
Comment on the comment below:
"I've discussed this with him offline. He's left out quite a bit of critical context: He's running a script. He's changing that script. He wants the script to only run the changed code, which isn't possible."
..I wouldn't say I'm selectively choosing to not run part of the code, which is how I interpret the above. My code uses loops to generate many variations of a few kinds of objects. So some of those variations would still be good and not need to be re-calculated, while others -would- need to be re-calculated. So the code would have to be changed (an if-else statement should do the trick), so that for each iteration of the loop, either it re-calculates, or it loads up the object that was created the last time.
Edit: Note some interesting opinions getting passed through Blender Artists
Edit 2: It's now looking like the answer to this question involves saving the object as a blend. So the first answer, which mentions blend-libraries, may be on the right track. I'm now researching how to save and load blend files with python (eta at least a few days). The question is how to do this while only saving precisely what I want to save so I get everything I need without wasting memory. ..and doing it quickly and elegantly, etc..