deleting unused mesh data

For practise I am making a simple 3d scene with scripting and at this point I have
bunch of mesh data which are not linked to objects. I would like delete those
OR revert blenders settings to defaults if them are stored somewhere. All objects
which are usable are linked to scene.

all unused datablocks are “delete” if you save, and re-open the blend (some times with erase all with X key work fine).

if you have problems, use SHIFT+F4, this window is a browser for internal library of the blend opened, and you can select mesh, materials or everithing, anf press F key for fake o unfake each one.

bye. :slight_smile:

cool to see you’re back at it!

first off, this is your friend:
keep it with you always (it can be dloaded from the download>>documentation menu)

ok, that aside:

Blender.Mesh.Get(“name”) will return a mesh by the name of “name”
and Blender.Mesh.Get() will return a list of all meshes in current scene.

then, assuming you assigned it to an object named ‘me’, me.users is an int that contains the number of objects linked to this mesh.

if it’s zero, the mesh is not linked to anything… I.E. it’s unused.
therefore, you can get rid of it with Blender.Mesh.Unlink(“name”)

oh, and you can get the name from the object, look in the api docs (linked to above) and find it. HINT: it’s a variable, a string

post if you have any questions, and post the finished code snippit when you’re done with it, I want to see how you do it.

Unused mesh data finally gone. How it got done was not on
purpose, basically: Quitting Blender and opening it few times.

thanks Jesse and CJD

dear j, this is a python forum, and for this jeseethemind give you the right python response (my poor english, my god…).

y only write the manually way of delete unused data.


if you just want to save some memory do me.verts= None

hmm, that’d work.

here’s how I’d do it: (not using correct syntax, you’ll learn better looking it up yourself)

-imports #import Blender etc.

-get mesh list (using Blender.Mesh.Get()) #remember to assign it to a variable
-start loop 1, for each mesh in the list:
-get users (using whatever.users)
-if users == 0:
-me.faces = none, me.verts = none (or just me.verts, havent tried it)
-unlink it

this will get rid of all data associated with the meshes, then unlink them so their datablock will be removed on restart.

Thanks for all the advice,
Something like this, but not exactly?

# note: these code does not run
import Blender as B
from Blender import*
list = B.Mesh.Get()
   for i in list:
        if i.users == 0:
              i.verts = None

yep, that’d be perfect. Should run too if you put a space between import and the *.

It still does not run, doesn´t like the:


and mesh data does not get empty.


Thanks MvGulik
No more trying to run unlinking of mesh from object,
when it ain´t gona ever run in current release of Blender.

That supplement > unlinking scene. Would do it i guess,
but i would have to write too much of stuff that i can
only write partly correct at this point. This would be
such unoptimal method:

  1. Store scene name to variable
  2. Make a new scene
  3. Change original scene name
  4. Get list of all meshes which have greater than zero users
    and put that to variable
  5. Link the list´s objects to the new scene
  6. Delete original scene by unlinking it

hmm. Well it doesn´t look all that horrid, I will put couple
hours to taking a shot at this still. Its about learning python
for me, but originally cleaning the Oops and well flushing the
memory but still leaving Blender scene when quittting to where
it was.

if you wanted to reinvent computer you would have
to reivent the wheel, no, you would have to reinvent
fire, no, you would have to be a monkey.