Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/node_BMeshview.py
Created June 2, 2014 13:07
Show Gist options
  • Save zeffii/9cacb70bc8194d4dd448 to your computer and use it in GitHub Desktop.
Save zeffii/9cacb70bc8194d4dd448 to your computer and use it in GitHub Desktop.
def remove_non_updated_objects(self, obj_index, _name):
meshes = bpy.data.meshes
objects = bpy.data.objects
objects_to_reselect = [] # 1
for i in bpy.context.selected_objects:
objects_to_reselect.append(i.name) # 2
i.select = False
objs = [obj for obj in objects if obj.type == 'MESH']
objs = [obj for obj in objs if obj.name.startswith(_name)]
objs = [obj.name for obj in objs if int(obj.name.split("_")[-1]) > obj_index]
# select and finally remove all excess objects
for object_name in objs:
objects[object_name].hide_select = False
objects[object_name].select = True
bpy.ops.object.delete()
# delete associated meshes
for object_name in objs:
meshes.remove(meshes[object_name])
# reselect
for name in objects_to_reselect: # 3
bpy.data.objects[name].select = True # 4
# fingers crossed.
@enzyme69
Copy link

enzyme69 commented Jun 2, 2014

This is the behaviour that I wanted. It deselect and reselect the OBJ. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment