Play a sound in Sketchup

Hi. I just wanted to ask if anyone could help me regarding this sketchup UI module. im new to this programming so please bare with my technical difficulties.

I am trying to play a sound in Skethup. when i enter the code in ruby console, it returns nil.
here is my code:

UI.play_sound (“Plugins/polaroid.wav”)

I have already put a polaroid.wav file in my plugin directory of Sketchup but it still dont play a sound.

I could not figure out why.

You need to pass the full file-path to the method.
e.g. UI.play_sound(File.join(Sketchup.find_support_file(‘Plugins’), ‘polaroid.wav’))

Rather than having various files ‘lose’ in the Plugins folder I recommend that you make a subfolder for your extension which contains any files it needs, you can then add that into the file-path…
Also you could check the file exists before trying to play it.

1 Like

Also please use a more descriptive topic caption. “Sketchup Ruby API” is far too vague.


Moved to the right category and… edited now … :blush:

1 Like

I try this code in Ruby Console:

soundpath = File.join(Sketchup.find_support_file(‘Plugins’, ‘polaroid.wav’))

it still dont play a sound. but return the attached pic.
Im sorry, I not good on this. My first time trying to learn.


You didn’t form the soundpath as I suggested.
Find the Plugins folder then use the File tools to add the wav file onto it so you then have a valid file-path.
The way it is now you’re trying to pass 2 arguments to find_support_file - it only expects 1, so the wav file part is ignored !


I still don’t know where I got wrong this time. The sound wont play. Or don’t I follow the right procedure again?

UI.play_sound(File.join(Sketchup.find_support_file(‘Plugins’), ‘james’, ‘polaroid.wav’))
You can’t mess with the find_support_file’s path.
Find it then add the subfolder and wav name and it should work…
Because you don’t have file-types set to be displayed we are guessing it’s a .wav file !!!

I’m sorry but it still wont work :frowning:

I tried using the same syntax in returning string path to the toolbar’s icon pic. to find if it works. Surprisingly, it works. I dont know why it dont works in playing a sound. The png file for the icon’s pic is in the same folder as the wav file for playing the sound.

here is the code:

toolbar = “Test”

cmd =“Test”){
UI.messagebox(“Gwapo Si James”)
UI.play_sound(File.join(Sketchup.find_support_file(‘Plugins’), ‘james’, ‘polaroid.wav’))


cmd.small_icon = File.join(Sketchup.find_support_file(‘Plugins’), ‘james’, ‘james.png’)
cmd.large_icon = File.join(Sketchup.find_support_file(‘Plugins’), ‘james’, ‘james.png’)
cmd.tooltip = “Test Toolbars”
cmd.status_bar_text = “This is SketchUp/Ruby - Toolbar Button Test”

toolbar = toolbar.add_item cmd

the toolbar’s icon displays the png file, written in the code, as it intended. But no sound was played, even entering the single line for playing the sound in ruby console.

Are you sure the wav file is there ?
Does the wav file open/play outside of SketchUp ?
Have you tried another wav file etc ?

There’s lots of possibilities to test…

The forum is replacing quotes with smartquotes. See:

Unfortunately, however I tried, it wont work. I changes other wav file, and making sure it is a valid file etc.,


Can you post the .wav file here ?

Thanks for advices. It seems that the audio file is the problem. I tried various softwares for wav files conversions and only few of those output could be use to allow UI.play_sound to execute.

Certain bitness, what ? Give us a clue.