Starting blender with a clean slate? A really clean one.

I was working on a small script to automatize the creation of a serie of object in the viewport.

When I launch my script, it creates a lot of object, when I am not satisfied I delete them right?
But I end up with a pile of ghost meshes that doesn’t show in blender and the outliner, but are still present when using Mesh.Get()…

I had the surprise to see that even though I pressed “x” to delete all the previous objects I generated, their still was some “phantom” mesh in the scene…

Typing


Me=Mesh.Get()
print Me

returns me


[[Mesh "Mesh.009"], [Mesh "Mesh.045"], [Mesh "Mesh.046"], [Mesh "Mesh.047"]]

Intrigued, I added some more objects. Simple cubes. And deleted them.

Typing


Me=Mesh.Get()
print Me

returns me


[[Mesh "Cube.001"], [Mesh "Cube.002"], [Mesh "Cube.003"], [Mesh "Cube.004"], [Mesh "Mesh.009"], [Mesh "Mesh.045"], [Mesh "Mesh.046"], [Mesh "Mesh.047"], [Mesh "Cube"]]

:mad: how do I ask Blender to start with a totally new scene, with nothing inside… It’s messing with my iterative code…

I tried Scene.unlink but it works only for the objects (I have an empty list of objects)…

deleting the objects dosnt remove their meshes (they just have zero users, save and reload and they will be removed)

Guess it will have to do…

:confused: But there is no way to do that from the script? Like Scene.New or something?

I had similar situation some time ago. I think it’s the easiest to save a blank file with your script and do the Ctrl-o while you write/debug.

Here’s a little script that I nicked (I think) from Aspn Cookbook pages and refactored it for Blender. What it does is it prints out the tracebak very nicely. So if your script crashes, you can run it trough this one (select from menu). (run this script and select the script you’re working on from menu - that’s all, then you’ll find a new ErrorReport text in text editor - get it from the menu and save if you need)

There is a caveat - your script that you’re working on must be saved to disk first. This is arbitrary, saves your work if Blender crashes.

Check it out if you wish so …


import Blender, sys, traceback, cStringIO

def print_exc_plus ():
	tx = cStringIO.StringIO()
	tb = sys.exc_info()[2]
	stack = []

	while tb:
		stack.append(tb.tb_frame)
		tb = tb.tb_next

	traceback.print_exc()
	tx.write('
LOCALS BY FRAME, INNERMOST LAST:')

	for frame in stack:
		tx.write('
' * 2 + '=' * 80 + '
' * 2)
		tx.write('FRAME %s IN < %s > AT LINE %s' % (frame.f_code.co_name, frame.f_code.co_filename, frame.f_lineno))
		tx.write('
' * 2 + '=' * 80 + '
')

		for key, value in frame.f_locals.items():
			tx.write('
' * 2)
			tx.write('	%20s = ' % key)

			try: tx.write('%s' % value)

			except: tx.write('<ERROR WHILE PRINTING VALUE>')

		tx.write('
')

	tx.seek(0)
	Blender.Text.New('ErrorReport').write(tx.getvalue())
	tx.close()

if __name__ == '__main__':
	alltxt = Blender.Text.Get()
	option = 'SELECT SCRIPT TO CHECK :%t'

	for i in xrange(len(alltxt)): option += '|' + alltxt[i].getName() + '%x' + str(i)

	menu = Blender.Draw.PupMenu(option)

	if menu != -1:
		if alltxt[menu].getFilename():
			try:
				filename = Blender.Text.Get(alltxt[menu].getName()).getFilename()
				execfile(filename)

			except: print_exc_plus()

		else: Blender.Draw.PupMenu('ERROR :%t| save the script to disk first!')


Scene.New()? I don’t think meshes span scenes.
The API is your friend :slight_smile:
http://www.blender.org/documentation/244PythonDoc/Scene-module.html

But wouldn’t that also delete his script? Just guessing.

scenes can share meshes and objects between eachother - text files are stored per blend

Do they by default? I mean, are all the meshes accessible from any scene, or do you have to link them to an object in the scene?

by default… I guess so. there is no restriction.

blender works like this…

scene->object->obdata

meshes are obdata. so be sure not to confuse meshes and objects.

scenes can access any object and objects can access any obdata.

true. basically, when u press “x” you’re deleting the Object, but not the mesh. So you must find a way to delete the mesh.
it’s kinda funny how i know enough to know what’s wrong, but not enough to actually help :stuck_out_tongue:
sorry

if you want to free most memory from your meshes - just do this before your script quits…


for me in myMehses:
  if not me.users:
    me.verts = None

Ah, thanks. I’ll have to have a play and see whats what, but cheers.

scene->object->obdata

:smiley: kind of funny that when deleting an object, the associated mesh persists…
But as multiple objects can access an obdata it seems obvious why it is that way…

What ideasman posted about users makes me think there must be a way to get rid of the unused meshes…

I will check that one…

Oh… btw does the way I build my mesh influence the way it is deleted? (I use a slightly modified JMSoler script, but I heard NMesh was deprecated, maybe there is a better way)

def makecube(x,y,z,name):
    vertices_list=[ 
        [-0.5*x,-0.5*y,-0.5*z],
        [-0.5*x,0.5*y,-0.5*z],
        [0.5*x,0.5*y,-0.5*z],
        [0.5*x,-0.5*y,-0.5*z],
        [-0.5*x,-0.5*y,0.5*z],
        [-0.5*x,0.5*y,0.5*z],
        [0.5*x,0.5*y,0.5*z],
        [0.5*x,-0.5*y,0.5*z]
    ]
    
    faces_list=[[0,1,2,3],
        [7,6,5,4],
        [3,7,4,0],
        [5,6,2,1],
        [4,5,1,0],
        [2,6,7,3]]
    
    A_CUBE_MESH=NMesh.GetRaw()
    
    for coordinate in vertices_list:
        A_VERTEX=NMesh.Vert(coordinate[0], coordinate[1], coordinate[2])
        A_CUBE_MESH.verts.append(A_VERTEX)
    
    for thisface in faces_list:
        A_FACE=NMesh.Face()
        for vertexpos in thisface:
            A_FACE.append(A_CUBE_MESH.verts[vertexpos])
        A_CUBE_MESH.faces.append(A_FACE)
    
    #NMesh.PutRaw(A_CUBE_MESH,name) 
    
    scn=Scene.GetCurrent()
    ob=scn.objects.new(A_CUBE_MESH,name)
    
    return ob