-
-
Save zeffii/9cacb70bc8194d4dd448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the behaviour that I wanted. It deselect and reselect the OBJ. Cheers!