[Bf-python] purging datablocks via python

Joe Eagar joeedh at gmail.com
Wed Jan 18 01:11:28 CET 2006


Tom M wrote:
> Hi,
>
> a script author mentioned the following,
>
> [QUOTE]Honestly, the only major Blender Python issue plaguing me is
> the lack of ability to purge the Library properly.  No matter what
> code I add to the script to try to get Blender to cleanup old unused
> Datablocks (I _have_ to create alot of temporary objects in my
> script), the _only_ way to get rid of the data is to save, close
> blender, reopen the file, save, close, & reopen.  The filesize of the
> .blend for our project drops from 800 MB to 75MB after doing
> this.[/QUOTE]
>
> This is probably something for 2.42 but, is there a workaround?  I
> seem to recall mention of a way to hackishly do this via python...
>   
This was blender's first undo system, actually.  By saving data blocks 
users could retrieve deleted meshes right up until they exited blender 
or loaded another file.

The current undo uses this still.  Of course, theres no reason why a 
Library block with no users can't be deallocated.  A python function to 
check this and deallocate would be a good idea, if annoying to implement 
across the board for each blender python data type. 

Keeping the blocks out of the undo data may be a little more difficult, 
but should still be possible with good design.

Maybe implement the del operator in, say, Mesh, so that:

if (mesh->id.users==0) {
   BLI_remlnk(G.main->meshs, mesh);
   unlink_mesh(mesh);
   free_mesh(mesh)
else {
/*maybe print a warning or raise some sort of CouldNotDelete exception*/
}

Even undo data won't care, since *supposedly* if mesh->id.users==0, 
there are absolutely NO pointers to mesh except for the linked list in 
G.main.  There may be hacks that violate this, but I don't expect it; 
this design principle has been maintained fairly well.

joeedh



More information about the Bf-python mailing list