Looking to create a script that would play an audio file on starting rendering.

Looking to create a script that would play an audio file on starting rendering.

Matthew_Polewiak
Contributor Contributor
1,185 Views
7 Replies
Message 1 of 8

Looking to create a script that would play an audio file on starting rendering.

Matthew_Polewiak
Contributor
Contributor

I would like to create a script that plays an audo file (mp3 format though I can convert it if needed) whenever I start the rendering process (I usually start it with the shift +Q/Render production option).

I tried creating the script through chat gpt but it seems the script that I was given (written below) doesn't work in 2024 version of 3ds max.

 

global renderEvents = undefined

fn playSoundOnRenderStart =
(
local soundPath = @"C:\Path\to\your\sound\clip.mp3" -- Replace with the actual path to your sound clip
playSound soundPath
)

fn onRenderStart evs =
(
if evs.startRendering do
(
playSoundOnRenderStart()
)
)

fn setupRenderEvents =
(
if renderEvents == undefined do
(
renderEvents = dotNetObject "Autodesk.Max.RenderEvents"
dotNet.addEventHandler renderEvents "RenderStart" onRenderStart
)
)

setupRenderEvents()

 

0 Likes
Accepted solutions (1)
1,186 Views
7 Replies
Replies (7)
Message 2 of 8

dmitriy.shpilevoy
Collaborator
Collaborator
Accepted solution

Try this

 

 

(
player = dotnetobject "System.Media.SoundPlayer"
path = @"c:\Windows\Media\chimes.wav"
player.SoundLocation = path
player.Load()
function renderPlay = (
	format "playing\n"
	player.Play()
)

rollout r_play "play" (
	button bt_play "play" width:120 --align:#left
 	on r_play open do (
 		callbacks.removescripts id:#rplaycb
 		callbacks.addscript #preRender renderPlay id:#rplaycb
 	)
	on r_play close do (
		callbacks.removescripts id:#rplaycb
	)
	on bt_play pressed  do (
		renderPlay()
	)
)
createDialog r_play 200 60
)

 

 

0 Likes
Message 3 of 8

Matthew_Polewiak
Contributor
Contributor

It works thanks a lot,

Do you know how can I make 3Ds Max run the script automatically on launch?

0 Likes
Message 4 of 8

dmitriy.shpilevoy
Collaborator
Collaborator

Run

GetDir #startupScripts

in listener and put script there. Note that as it is script will open rollout each time and stop working if you close it.

You can leave the sound stuff and remove rollout from it, but then it will keep callbacks registered.

0 Likes
Message 5 of 8

Serejah
Advocate
Advocate
this kind of script deserves its own macro button to toggle on/off state
Message 6 of 8

denisT.MaxDoctor
Advisor
Advisor

@Matthew_Polewiak wrote:

I would like to create a script that plays an audo file (mp3 format though I can convert it if needed) whenever I start the rendering process (I usually start it with the shift +Q/Render production option).

 


Is there some special point to this, or is it just to make the process less boring?

0 Likes
Message 7 of 8

Matthew_Polewiak
Contributor
Contributor
The latter option i suppose, it's kind of an inside joke between me and my brother.
0 Likes
Message 8 of 8

denisT.MaxDoctor
Advisor
Advisor

@Matthew_Polewiak wrote:
The latter option i suppose, it's kind of an inside joke between me and my brother.

then you better go to Reddit

0 Likes