def switch_baked_material(show_bake_material, affect):
    current_bake_type = bpy.context.scene.bake_settings.get_current_bake_type()
    material_name_suffix = constants.Material_Suffix.bake_type_mat_suffix[current_bake_type]
    if (affect == 'active'):
        objects = [bpy.context.active_object]
    elif (affect == 'selected'):
        objects = bpy.context.selected_editable_objects
    elif (affect == 'visible'):
        objects = [ob for ob in bpy.context.view_layer.objects if ob.visible_get()]
    elif (affect == 'scene'):
        objects = bpy.context.scene.objects
    all_mats = bpy.data.materials
    baked_mats = [mat for mat in all_mats if (material_name_suffix in mat.name)]
    for obj in objects:
        if (current_bake_type != 'pbr'):
            baked_ao_flag = ((getattr(obj, 'ao_map_name') != '') or (getattr(obj, 'lightmap_name') != ''))
            if (not baked_ao_flag):
                continue
        for slot in obj.material_slots:
            if show_bake_material:
                for baked_mat in baked_mats:
                    if (baked_mat.name == ((slot.material.name + material_name_suffix) + obj.bake_version)):
                        slot.material = baked_mat
            elif (material_name_suffix in slot.material.name):
                bake_material = slot.material
                index = bake_material.name.find(material_name_suffix)
                org_mat = all_mats.get(bake_material.name[0:index])
                if (org_mat is not None):
                    slot.material = org_mat
def switch_baked_material(show_bake_material, affect):
    current_bake_type = bpy.context.scene.bake_settings.get_current_bake_type()
    material_name_suffix = constants.Material_Suffix.bake_type_mat_suffix[current_bake_type]
    if (affect == 'active'):
        objects = [bpy.context.active_object]
    elif (affect == 'selected'):
        objects = bpy.context.selected_editable_objects
    elif (affect == 'visible'):
        objects = [ob for ob in bpy.context.view_layer.objects if ob.visible_get()]
    elif (affect == 'scene'):
        objects = bpy.context.scene.objects
    all_mats = bpy.data.materials
    baked_mats = [mat for mat in all_mats if (material_name_suffix in mat.name)]
    for obj in objects:
        if (current_bake_type != 'pbr'):
            baked_ao_flag = ((getattr(obj, 'ao_map_name') != ) or (getattr(obj, 'lightmap_name') != ))
            if (not baked_ao_flag):
                continue
        for slot in obj.material_slots:
            if show_bake_material:
                for baked_mat in baked_mats:
                    if (baked_mat.name == ((slot.material.name + material_name_suffix) + obj.bake_version)):
                        slot.material = baked_mat
            elif (material_name_suffix in slot.material.name):
                bake_material = slot.material
                index = bake_material.name.find(material_name_suffix)
                org_mat = all_mats.get(bake_material.name[0:index])
                if (org_mat is not None):
                    slot.material = org_mat