1
$\begingroup$

When extracting data via temporary mesh, like this:

mesh = object.to_mesh(bpy.context.scene, apply_modifiers=True, settings='RENDER')

Do I need to delete this mesh, after I'm done extracting data? Will it stay in memory after running the script?

$\endgroup$

1 Answer 1

0
$\begingroup$

Yes, you need to deleted them by yourself.

If you print that mesh object in script multiple times, you will find out that the name change by adding post-fix serial number to its based name as follow:

<bpy_struct, Mesh("Suzanne.002")>
<bpy_struct, Mesh("Suzanne.003")>
<bpy_struct, Mesh("Suzanne.004")>

And if you are using Blender 2.8, in the Outliner Panel, you can change display type from View Layer to Orphan Data (what an adorable name), the meshes you created will stay at there. You can pin them by pressing the cross button, making a fake user to let Blender keep the data-block.

Orphan data create by object-to_mesh

If you need to delete it in script, you cannot del mesh since the object data-block was already binded in to bpy.data.meshes, use bpy.data.meshes.remove(mesh) instead to delete it.

$\endgroup$
4
  • $\begingroup$ Thanks for the answer! So what is the best way to delete this mesh when I'm done with it? Also reloading the file removes the orphan meshes right? $\endgroup$
    – user56873
    Commented May 5, 2019 at 15:13
  • 1
    $\begingroup$ @LennyWhite blender.stackexchange.com/questions/27234/… $\endgroup$
    – HikariTW
    Commented May 5, 2019 at 15:16
  • 1
    $\begingroup$ That post shows how to delete an object, I need to delete the mesh. I tried this, and it seems to work bpy.data.meshes.remove(mesh). $\endgroup$
    – user56873
    Commented May 5, 2019 at 15:27
  • $\begingroup$ The last voted answer show how to make it. The data was references in bpy.data.meshes, use the method remove() to delete it. bpy.data.meshes.remove(the_suzanne) $\endgroup$
    – HikariTW
    Commented May 5, 2019 at 15:34

You must log in to answer this question.