deleting objects with type ?

how can you delete all object in scene of a certain type like MESH or Curve

but not the other ones

i can make a list and check but problem is how you delete one object without changing the intitial list ?

an example would be nice here

Thanks and happy 2.5

for ob in
    if ob.type == 'MESH':

That won’t work because it you delete an item from the list doesn’t get dynamically updated during your for loop.

Or maybe it will work – too lazy to actually test – but the list still won’t get updated either way.

You need to start over at the beginning of the list every time you delete an object to make sure your references are valid so you don’t crash blender…just the way things work unfortunately.

guess it changes the list and it does not like it

but found another way not elegant but it works fine

#    lets remove all the objects except the basic one
    for each in range(len(sceobj)):
        print ('KK =',kk1,'Object name =',sceobj[each].name,' Type=',sceobj[each].type)
        if sceobj[each].type =="MESH" or sceobj[each].type =="TEXT" or sceobj[each].type =="CURVE" or sceobj[each].type =="EMPTY":
    print ()
    print ('List of delete objects=',listname1)
    print ()
    print ()
    print ('Qty objects to delete =',len(listname1))
    print ()
    for i1 in range(len(listname1)):
        print ('KK2 =',kk2,'Delete  Object name =',listname1[i1])
        ob1 =[listname1[i1]]
    print ()
    print ()

that one works fine
but wish there was a more elegant way of dong it !

is it necessary to have the unlink and the remove commands to delete and object ?

and there must be another way using or BPYtype to deletes objects but how ?


You can’t delete an object if it’s linked into a scene so…

I tried to get a scene.objects.delete() function in with the scene.objects.unlink() bugfix (which was actually deleting objects instead of just unlinking) but it was veto’d by Campbell.

ok so you need the unlink and then the remove one for BPU.OPS

now how to do it with other way in BPY.DATA or BPY.type ?