Rigidbody.object_remove doesn't work anymore

Hi…,

my following script from last year is throwing this error in Blender 4.1: “# RuntimeError: Error: ViewLayer ‘View Layer’ does not contain object ‘Export.000’”.

    if new_obj.rigid_body is not None:
        bpy.context.view_layer.objects.active = bpy.data.objects.get( new_obj.name ) # RuntimeError: Error: ViewLayer 'View Layer' does not contain object 'Export.000'
        bpy.ops.rigidbody.object_remove()

How to remove the rigidbody from my object?

Thanks

Michael

Hi…,

I’ve fixed it with this code:

    if new_obj.rigid_body is not None:
        selected_objects = [
            new_obj, 
            bpy.data.objects[new_obj.name]
            ]  
        with bpy.context.temp_override(active_object=new_obj, selected_objects=selected_objects):
            bpy.ops.rigidbody.object_remove()

Thanks

Michael