 |
|
Exchange Forum >
ActiveX and VBA
Playing Sounds in AutoCAD |
|
|
|
|
|
| Playing Sounds in AutoCAD |
#11 |
|
|
Nugent |
 |
|
Join Date: |
|
10-05-2007 | |
I discovered a problem with PlaySound this past week and maybe someone can help me solve it. The program will only play sound files if the folder name and the sound filename don't have any spaces. I tried a few things like adding Chr(34) for a quote (") to the beginning and end of the path and filename in VBA, but it still didn't work. However, it does works if you copy the sound file to a folder that has no spaces in the name, and then rename the sound file name to remove any spaces in the name. I also tested PlayWav inspired by the program that Dante posted and it allows spaces in the folder name and the wav sound filename, but unlike PlaySound it doesn't play the sound in the background. I'd appreciate any help or ideas.
Thanks,
Nugent
| |
|
| Playing Sounds in AutoCAD |
#12 |
|
|
Dante |
 |
|
Join Date: |
|
08-13-2007 | |
I couldn't figure it out either. I even crashed AutoCAD testing some different options in VBA. But just to play it safe, I revised your code to have AutoLISP handle the space issue. You'll need a folder to use for the program that doesn't have any spaces. I used C:\Music for the example in the code, but it can be called anything.
Dante
Code:
(defun PlaySound (SoundFilename / Ext PlaySoundExt UserS5)
(if (setq Ext (vl-filename-extension SoundFilename))
(setq Ext (strcase Ext t))
)
(if (and (findfile SoundFilename)(member Ext (list ".wav" ".mp3" ".mid" ".cda" ".wma")))
(progn
(if (wcmatch SoundFilename "* *")
(progn
;The following foldername can be any name without spaces.
(setq PlaySoundExt (strcat "C:\\Music\\PlaySound" Ext))
(if (findfile PlaySoundExt)
(progn
(vl-file-delete PlaySoundExt)
(vl-file-copy SoundFilename PlaySoundExt)
)
(vl-file-copy SoundFilename PlaySoundExt)
)
(setq SoundFilename PlaySoundExt)
)
)
(setq UserS5 (getvar "USERS5"))
(setvar "USERS5" SoundFilename)
(command "vbaload" "PlaySound.dvb")
(command "-vbarun" "thisdrawing.PlaySound")
(command "vbaunload" "PlaySound.dvb")
(setvar "USERS5" UserS5)
)
(princ (strcat "\n" SoundFilename " file not found or is not a valid sound file."))
)
(princ)
)
(defun StopSound (SoundFilename / Ext UserS5)
(if (setq Ext (vl-filename-extension SoundFilename))
(setq Ext (strcase Ext t))
)
(if (and (findfile SoundFilename)(member Ext (list ".wav" ".mp3" ".mid" ".cda" ".wma")))
(progn
(if (wcmatch SoundFilename "* *")
;The following foldername can be any name without spaces.
(setq SoundFilename (strcat "C:\\Music\\PlaySound" Ext))
)
(setq UserS5 (getvar "USERS5"))
(setvar "USERS5" SoundFilename)
(command "vbaload" "PlaySound.dvb")
(command "-vbarun" "thisdrawing.StopSound")
(command "vbaunload" "PlaySound.dvb")
(setvar "USERS5" UserS5)
)
(princ (strcat "\n" SoundFilename " file not found or is not a valid sound file."))
)
(princ)
)
| |
|
| Playing Sounds in AutoCAD |
#13 |
|
|
Nugent |
 |
|
Join Date: |
|
10-05-2007 | |
Dante,
I've been testing some sound files with your revised version and it works great. I'm able to play a lot more songs without going to any trouble as far as copying and renaming sound files.
| |
|
| Playing Sounds in AutoCAD |
#14 |
|
|
KyleMcClure |
 |
|
Join Date: |
|
07-14-2008 | |
Dante & Nugent,
I tested PlaySound, and it works great no matter how deep the music file is in any folder location. It would be nice to add a menu selection if that's possible.
Kyle
| |
|
| Playing Sounds in AutoCAD |
#15 |
|
|
Dante |
 |
|
Join Date: |
|
08-13-2007 | |
Kyle,
Thanks for your suggestions.
Dante
| |
|
|
|
|
|