We have a long script that we run on a completed folder of project drawings. When the script is completed it would be nice to have AutoCAD play a sound or a music file. We've looked into AutoCAD help but don't know what to search for. Any help would be appreciated.
You can use the VBA beep sound using one of these commands. I think the second example is safer in case there's a problem with the commands issued.
(command "vbastmt" "beep")
(vl-cmdf "vbastmt" "beep")
Have you tried using the Windows Mplay32.exe with the startapp function? It's fairly easy to use. The only drawback is that it displays a small Mplay32 dialog while the wav file is being played. If this is not obtrusive in your script here is an example. Make sure the wav-file path and filename exist on your computer terminals.
VBA has some built in modules for playing wav files. Here's one example that you can play around with. I'm not sure about all the options for the Module and Flags parameters, but you can experiment with those as well. You can change the wav file path and filename to one that you want to test out.
Dante
Code:
Private Declare Function PlaySound Lib "Winmm.dll" _
(ByVal SoundName As String, ByVal Module As Long, ByVal Flags As Long) As Long
Sub Play()
'Change the wav sound file to one that you prefer.
PlaySound "C:\Program Files\NetMeeting\TestSnd.wav", 0, &H20000
End Sub
Dante,
Why not have the VBA code driven by AutoLISP similar to the thread on VBA code with AutoLISP? This way someone could easily try a new wav sound from the command line without knowing any VBA. They could also easily use it in a script. Here’s my version of PlayWav.
Code:
Example for testing on the command line:
(PlayWav "C:\\Windows\\Media\\tada.wav")
Example for writing to a script file:
(write-line "(PlayWav \"C:\\\\Windows\\\\Media\\\\tada.wav\")" ScriptFile)
AutoLISP code
Code:
(defun PlayWav (WavFilename / UserS5)
(if (and (findfile WavFilename)(= (strcase (vl-filename-extension WavFilename) t) ".wav"))
(progn
(setq UserS5 (getvar "USERS5"))
(setvar "USERS5" WavFilename)
(command "vbaload" "PlayWav.dvb")
(command "-vbarun" "thisdrawing.PlayWav")
(command "vbaunload" "PlayWav.dvb")
(setvar "USERS5" UserS5)
)
(princ (strcat "\n" WavFilename " file not found or is not a wav file."))
)
(princ)
)
VBA code
Code:
Private Declare Function PlaySound Lib "Winmm.dll" _
(ByVal SoundName As String, ByVal Module As Long, ByVal Flags As Long) As Long
Sub PlayWav()
Dim WavFilename As String
WavFilename = ThisDrawing.GetVariable("USERS5")
PlaySound WavFilename, 0, &H20000
End Sub
I don't seem to have the WinAmp program installed on my computer. When I searched on the internet I found a few websites to download the program, but I also came across a few websites to fix problems with WinAmp.exe. Have you found it safe to use on your computer, and have they fixed these problems that these websites mentioned?
Your program is specific to your computer's file structure. If I understand the syntax you are using, I just need to use something like the following to play my music file. Is this correct?
I just downloaded WimAmp from the link below. Everything seems to be working and playing fine. In the download screens I always check that I'm not interested in emails about other related products etc. It will play just about any sound file including avi, mid, midi, mp3, wma, wav and many more types. And the best thing, is that it's free!
I've been doing some research after testing somethings in PlayWav and came up with this new version named PlaySound. Unlike PlayWav this version plays in the background. It can play several types of sound files. However, I have only tested wav, mp3, mid, cda, and wma sound files so far. You can add other extensions to test out, by adding them to the lisp file. The StopSound function is useful for stopping one song before playing the next one.
Nugent
Private Declare Function PlaySounds Lib "Winmm.dll" Alias "mciSendStringA" _
(ByVal strCommand As String, ByVal ReturnString As String, _
ByVal ReturnLength As Long, ByVal CallBack As Long) As Long
Function PlaySound()
Dim Filename As String
Dim lngReturn As Long
Dim str256 As String
str256 = String$(256, 0)
Filename = ThisDrawing.GetVariable("USERS5")
lngReturn = PlaySounds("Play " & Filename, str256, 255, 0)
End Function
Function StopSound()
Dim Filename As String
Dim lngReturn As Long
Dim str256 As String
str256 = String$(256, 0)
Filename = ThisDrawing.GetVariable("USERS5")
lngReturn = PlaySounds("Stop " & Filename, str256, 255, 0)
End Function