I'm trying to make a python script that splits alot of objects into its loose parts and i actually have gotten this to work but i encountered a bug that i don't fully understand and thus come to you to help me out!
I have the following code to manipulate each object that i need to have manipulated (and split):
for collection in bpy.data.collections:
if collection.name == "Render":
for object in collection.objects:
print("Manipulating object: {}".format(object.name))
# place at correct location and scale to the setting size
object.scale = scale
thickness = list(object.dimensions)[2]
location = [0 ,0, thickness/1000]
object.location = location
object.rotation_euler = rotation
# split the mesh
if object.type == 'MESH':
print("Splitting mesh")
bpy.ops.mesh.separate(type='LOOSE')
break # no need to check other collections
What happens is that all the objects that it iterates through are placed at the correct location and with the correct size and everything but only the last item in the list
collections.objects
is split into its loose parts but all the other objects are not.
Heres an image of the console:
Note that 5AD48 part shows up multiple times because it has been split.
My first thought was that its caused because once the body is split the collection is not the same anymore, so i tried copying the list but that just made it more buggy.
Anyone have a clue what causes this bug? Any insight will help!
Thanks in advance!