This is a very basic question about scripting, but I'm unable to find a useful answer.
I created a new .blend file and did the following:
- rename the default collection ("Collection") to
- rename the default cube object inside to
- rename the mesh inside that to
Now I want to write a Python script that will do the following:
- delete the data in
my_meshand replace it with a new mesh generated by Python code.
The reason I want to overwrite the mesh rather than generating a new one is that I'll be adding modifiers to the mesh and don't want them to disappear every time I re-run the script.
bpy.data.meshes['my_mesh'].from_pydata(...) doesn't work. (The error message is
Runtime error: internal error setting the array, which isn't super helpful.)
There is a similar question, Update/overwrite an existing mesh within a collection Python Blender, but the answer there works by deleting the old mesh and creating a new one with the same name, which will not preserve modifiers. Preserving modifiers is my main goal.
I'm using Blender 4.0 beta if that makes a difference.