Sounds

Hey guys, a bpy noob needs your advise.

I have really big scene with a lot of objects and I need to select all the objects that have the same sound file in their logic bricks. Any ideas how to do it?

I put this together real quick.

import bpy

scene = bpy.context.scene
my_sound = 'add_my_sound_file_here.wav'

#Get all objects in scene
for all_sound_objects in scene.objects:
    #Deselect all objects
    all_sound_objects.select = False    
    #Get all actuators for all objects   
    for all_actuators in all_sound_objects.game.actuators:
        #Check to see if actuator type is sound
        if all_actuators.type == 'SOUND':
            #Check to see if actuator sound is == to my sound
            if all_actuators.sound.name == my_sound:
                #Select all objects that has a sound actuator with my sound
                all_sound_objects.select = True
                #Make sure active object is one of the sound objects
                bpy.context.scene.objects.active = all_sound_objects

Thanks a lot. This is what I need.

why do you need to select objects with certain sound? If this is gonna be needed often, I make into small addon where you can select your sound from a selection. Where would you want it? Logic editor?

Yes, I needed to select all the objects with certain sound and replace it with another sound file. It has been done already, thanks.