0
$\begingroup$

My python command line shows names for objects that are not on the scene anymore when I try to autocomplete on

bpy.data.meshes

like

bpy.data.meshes['Cube']

is a valid reference even though there is no object named Cube on the scene anymore and no error or warning is issued, my script just goes on and does nothing .

I'm supposed to keep the Python API in sync with the scene manually - and in this case, how ? - or I'm missing something ?

$\endgroup$
2
$\begingroup$

bpy.data.meshes is all of the meshes in the all of the scenes. Meshes are different from objects, a mesh would be like the vertex positions while an object is made of a mesh, and contains the modifiers, materials, etc.

If you have an object selected you can see the name of the mesh by going to: Properties Panel > Data here you will see the name of the object's mesh, you can also get a list of all the meshes in the scene.

I am guessing that you have a cube, or an object that at one point was a cube and that is why the mesh name is Cube.

If you want to get rid of meshes that aren't currently being used then you can do something like this

import bpy
for mesh in bpy.data.meshes:
    if mesh.users == 0:
        bpy.data.meshes.remove(mesh)
$\endgroup$
  • $\begingroup$ yes, but why they don't go away when the associated object is not there anymore ? $\endgroup$ – user2485710 Oct 27 '14 at 20:36
  • $\begingroup$ @user2485710 if the mesh isn't being used by any objects, then it will be deleted on the next opening of Blender or by Ctrl + Shift + O, and reloading your current file. Just make sure to save first. If that doesn't get rid of it then it is still in use. A way to check if it is not in use is go to Properties Panel > Data and find the name of the mesh in the dropdown and see if there is a 0 beside it $\endgroup$ – BlendingJake Oct 27 '14 at 20:42
  • $\begingroup$ and what's the equivalent via Python ? How to force this update via script $\endgroup$ – user2485710 Oct 27 '14 at 20:45
  • $\begingroup$ @user2485710 check my original post, I updated it $\endgroup$ – BlendingJake Oct 27 '14 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.