I need to automate the process of joining similar objects from an imported .IFC file from Revit, this can take quite long time to sort out manually because this files can contain from 600 to 800 objects. The names have "." and ":" that I can use for separate the strings and join the same name objects.
I´m not a programmer, and I don't have experience with Python, but after some studying I manage to write this little script.
But I'm kinda lost here because it works fine with small list of objects but it crashes when dealing with longer lists.
In this one it runs ok, at the end all cubes are one object, spheres are other object, etc.
But when I run it against more longer lists of objects, it crashes Blender:
I'm assuming it has something to do when it tries to read objects that are no longer in the list.
Do you know if this assumption is correct? If so could you suggest a way to avoid the crash? Is there a better way to do what I'm trying to do based on the names of the objects?
This is script:
import bpy bpy.ops.object.select_all(action='DESELECT') bpy.context.view_layer.objects.active = None for obs in bpy.context.scene.objects: if obs.name in bpy.context.view_layer.objects: if obs.type == 'MESH': bpy.ops.object.select_all(action='DESELECT') nocolon = obs.name.rsplit(maxsplit=1, sep=':') print ('nocolon pass done for ' + nocolon) tname = nocolon.rsplit(maxsplit=1, sep='.') print ('nodot pass done for ' + tname) bpy.ops.object.select_pattern(pattern= tname+'*', case_sensitive=False, extend=True) print ('selection pass done for ' + tname) obs.select_set(True) print ('selection set done for ' + tname) bpy.context.view_layer.objects.active = obs print ('set active object done for ' + tname) bpy.ops.object.join() print ('join pass done for ' + tname) print ('iteration done for ' + tname) bpy.context.view_layer.objects.active = None else: print(obs.name + ' is not a MESH.') else: print('There is no ' + obs.name + ' in view_layer') bpy.data.objects.remove(obs) print('removed from data') print('script done')
I'm using Blender 2.81.16a