I'm sorry in advance if my script looks really messy and not optimised, it's my first time using python or a dev language for that matters.
I've tried to setup a script that, among other things, create and assign objects to a LP collection by checking their names.
When I'm trying to unlink the object from the HP collection they were taken from, the script successfully does the task, but still return an error, here's the script :
#List all object in scene that ends with remeshed and select them for obj in bpy.context.scene.objects: if obj.name.endswith("remeshed"): obj.select_set(True) #Create collection with selected objects bpy.ops.collection.create(name='LP') #Link collection to Scene Collection bpy.context.scene.collection.children.link(bpy.data.collections["LP"]) #Remove low poly objects from HP Collection for obj in bpy.context.scene.objects: if obj.name.endswith("remeshed"): bpy.context.view_layer.objects.active = obj bpy.ops.collection.objects_remove(collection = 'HP')
I've also tried to use
bpy.context.scene.collection.objects.unlink(obj) withtout success even with the HP collection selected and active.
Here's the error message :
Traceback (most recent call last): File "<blender_console>", line 4, in <module> File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\modules\bpy\ops.py", line 132, in __call__ ret = _op_call(self.idname_py(), None, kw) TypeError: Converting py args to operator properties: enum "HP" not found in ('LP')
And as I was saying the script does what I want and unlink the object from the HP collection, but since it returns an error, it stop when running it.
Thanks in advance for all the help and advise you could give me.