Delete An Object (or Mesh) From The Scene via Python

Hi All,

I would like to delete an object that I have imported into the scene via python.

Does anyone know the python code for doing that?:eyebrowlift:

Thanks

Deleting is impossible. The most you can do is unlink it. Then when the .blend file is saved and reloaded it will be gone.

From python. It’s possible to delete otherwise. But wait, the game engine can remove objects!

scene.objects.unlink(ob)

for meshes, wont remove but will free memory.
mesh.verts = None

removing mesh verts will still leave a mesh object, not so?

yes, the mesh is still there- just wont use as much memory in most cases (assuming it had verts&faces)

That doesn’t delete it. Come on Ideasman, more ideas! :slight_smile:
Or did we pass 42 already???

I’m sure there is some way to do it.
But why, Atom???

The way blender works internally assumes datablocks dont get deleated.
If we wanted to support it - its a single command and actually alredy support for Python Meshes that are never connected to an object. But once they are used by other parts of blender, removing it could break other parts of blender.

at times where Iv needed this functionality, I make a dummy mesh and re-use it.

I can delete an object from the user interface.
Right-Click Select Object then pressd the delete key-confirm.
Are you saying that Blender does not really delete anything?
This seems wrong!

it does, as far as I know…

I can delete an object from the user interface.
Right-Click Select Object then pressd the delete key-confirm.
Are you saying that Blender does not really delete anything?
This seems wrong!
Blender removes reference to that datablock. In case you delete a mesh object, you can still see the mesh in mesh list at Buttons Window -> Link and Materials -> ME:foo. In case it has zero in front of it, it is unlinked and will be removed permanently on reload of .blend file.

Some datablocks can be removed- they are exceptions Text, Objects, Scenes, Screens - But object datablocks are not- as BeBraw says.

I want to load a series of meshes over time.
These are typically mesh sequences exported from poser that have been animated with motion capture. Sometime I am faced with more than a 1000 meshes (high density) in a sequence.
So my thought was to simply load a new mesh on a frame change event to process the mesh sequence.
Without the ability to “truly” relase memory, the system will more than likley crash or come to a grinding halt.

if they are the same mesh with modified verts, see if you can use RVK’s
Maybe a script can be made to turn 1000’s of mehses into 1 mesh with rvks - as long as the vertex order and count are the same.

sometimes, i hate this behavior of blender. in case you want to overwrite a mesh object, you have to write that much extra stuff. you need to try to access the mesh if it’s there, doing an exception check, overwriting the old mesh data etc, instead of just erasing and recreate it.
i’ll probably never get, why a datablock with zero users cannot be simply deleted from memory. :no:

RVKs look promising, I have not heard of them till this post.

I am still concerned about how to read the next OBJ file into memory and not have it take up memory. This would mean I would have to re-write the OBJ import to simply read the vertext data, use that info to create RVKs, but not create a mesh object.

I still think it is odd that blender does not free memory.
In the C programming language there is malloc for allocating memory and it’s opposite “free” that actually frees up the memory that you have allocated. I wonder why the wise blender programmers would not simply run “free” after unlinking an object?

obj import for every frame is going to be totally slow (depending on obj size of course)- realy dont even bother doing it…

RVK’s are what you want- the size of the float array per key is nowhere near as bad.

The md2 importer creates RVK’s and is an OK example.

failing that- import all the data and some scripter here can help you make a script that does RVK’s from them all. but before that- check if poser can export MDD - a common format for storing vertex animation.

I know what you mean regarding memory, though it can be managed and Iv never found the problem too bad. perhaps some GetTempMesh utility (that can reuse the same mesh) would help.

There are fairly big advantages from a user perspective - so I dont complain too loud.