ScriptSpot

Forum topic · General Scripting

Making a script stop a render/network render until the script is okayed by a user

By Script_Butler · 2011-06-15

Description

Hi all, I started this script

http://www.scriptspot.com/3ds-max/scripts/hide-and-unhide-all-bones-and-…

and as you can tell it's very basic. Tassel came up with a more user friendly version and i'd like to enhance my script.

What I'd like to achieve is when this script is added to the pre-render scripts area, the script halts rendering until the relevant buttons are pressed. I'll add a "Render" button to it, but forst you pick "Hide Bones" to hide them and when you click the render button, max then renders the image.

The scripts i attached to my upload dont have any use inteface and just run "behind the scenes". This was intentional so that a user can add them and forget them.

But now i'd like to add some functionality, but still keep the script able to be used in the pre-render area if possible. Presently, with Tassel's version loaded in, the script opens the dialog, but the render happens anyway before you've told it to hide/unhide bones.

So, is there a fumction i can use to halt rendering while the script is active?

 

Comments (12)

good part

le1setreter · 2011-06-16

found a good part by ZeBoxx2 on cgtalk:

http://forums.cgsociety.org/showpost.php?p=5177416&postcount=6

i did a rough stitching of both scripts. put the attached version in your script/startup folder:


-- var for checking if bone check has been done before:
lastRenderChecked = false 

-- your script: 
-- Create a rollout
rollout roll_SB_Tools "SB Tools V1.0"
(
-- UI STUFF
group "Hide / Unhide (Bones And Helpers)"
(
button btn_SBHide "..:: HIDE ::.." width:85 height:24 align:#left tooltip:"Hide bones and helpers" across:2
button btn_SBUnhide "..:: UNHIDE ::.." width:85 height:24 align:#right tooltip:"UN-Hide bones and helpers"
)
group "Render"
(
button btn_render "..::RENDER::.." width:85 height:24 align:#left tooltip:"Press to start rendering"
)

HyperLink hl_homepage "..:: MY SCRIPTS ::.." address:"http://www.scriptspot.com/users/script-butler/" color:(color 255 255 255) hovercolor:(color 111 111 111) visitedcolor:(color 255 255 255) height:22 align:#center
-------------------------------------------------------------------------------------------------------------------------------------------------------
-- GROUP "Hide / Unhide (bones and helpers)"
-------------------------------------------------------------------------------------------------------------------------------------------------------
on btn_SBHide pressed do
(
hideByCategory.bones = true
hideByCategory.helpers = true
)

on btn_SBUnhide pressed do
(
hideByCategory.bones = false
hideByCategory.helpers = false
)
-------------------------------------------------------------------------------------------------------------------------------------------------------
-- GROUP "Render"
-------------------------------------------------------------------------------------------------------------------------------------------------------
on btn_render pressed do -- I'M UNSURE ON SCRIPTING COMMANDS TO MAKE THE RENDER HAPPEN
(
	lastRenderChecked = true -- disabling the check request window
	destroyDialog roll_SB_Tools -- closing current dialog
	max quick render -- starting the rendering
	lastRenderChecked = false -- enabling the check request window 
)
-------------------------------------------------------------------------------------------------------------------------------------------------------

) -- End of script

--Create the dialog and stuff -- disbaled dialog here:
-- createDialog roll_SB_Tools width:200 height:150








dialogMonitorOps.unRegisterNotification id:#renderConfirm
 
 fn renderConfirmationDialog = (
	
 	local hwnd = dialogMonitorOps.getWindowHandle()
	-- check if rendering is on progress and if bones has been checked before:
 	if (uiAccessor.getWindowText hwnd == "Rendering") and (lastRenderChecked == false) do (
 		if (querybox "Check Bones before Rendering?") do ( 
			-- cancel current rendering:
			uiAccessor.pressButtonByName hwnd "Cancel"
			-- creating dialog with bones
			createDialog roll_SB_Tools width:200 height:150
		)
	) 
 	true
 )
 
 dialogMonitorOps.enabled = true
 dialogMonitorOps.interactive = false
 dialogMonitorOps.registerNotification renderConfirmationDialog id:#renderConfirm

Attachments

Slight tweak....

Script_Butler · 2011-06-17

Thanks for this find le1setreter, i added it in to my startup scripts and did a test, it works well. But, when i add it to the Pre-render list, it's not so usable because it gets stuck in a loop. Because of the Render button on my script, when that is pressed, the script gets loaded again and you keep going through the same process.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Attached is a version where I've got rid of the render button and made the other two buttons render directly after they have been pressed. It's still got the loop problem, which can be negotiated but it's very annoying!

 

You have to say yes to "check bones before rendering", click the "hide" bones button, then click no to the "check bones before rendering when it comes up again.

I also deleted your part of the script and it seems to work still so i'm not entirely sure if your find was needed, but to be honest i don't quite know how i've made that happen without your part in.

 

I've attached it because i don't know how to add my script in to a window like you did.........by doing that, does all the colour formatting stay?

PS> I've managed to google how to create a scroll box, but when i add my script in (by copying and pasting directly from MAXScript) when i preview my post the scroll box dissapears......

Attachments

le1setreter · 2011-06-17

hi Script_Butler,

hmm... what do you exactly mean with "Pre-render list"? do you mean a callbacks.addScript #preRender? if yes is it really neccessary?
why not just put my script into script/startup?

i know the loop problem and it was annoying for me too. that has been the reason why i worked with the variable "lastRenderChecked" to not get the render confirmation request after being in the hide/unhide bones dialog.

the reason why i (or better said others) used the "dialogMonitorOps" is some kind of workaround to cancel/stop/kill the already startet render! i could not find another way to cancel a render via script.

using the messagebox, querybox or yesNoCancelBox also do some pausing while you can do changes before rendering but you are limited to the properties of these boxes/windows.

the code box can be done like this but without the space after "<":
< code>
your code in here (copyNpaste)
< /code>

Pre-render list

Script_Butler · 2011-06-18

Hello.

If you open up the Render dialog, there is a scripts rollout.

The first part is the Pre render list. Bassically i want my script to be added in there so the user can load it in just for certain maxfiles and whenever they hit render it loads the scripts listed.

If you look at my script page http://www.scriptspot.com/3ds-max/scripts/hide-and-unhide-all-bones-and-… you will see i included two scripts one for pre-render and one for pos-render.

The reason i want this script to be added in there is so that my script automatically gets run every time a render is needed and that way you don't forget to run the script or hide the bones.

If you put your version in to the startup folder it will run in every single maxfile. If you add it in the pre-render list it's on a per maxfile basis which is better in my opinion. Your version can be used either way though!

I guess theres no way around the loop? Could it be scripted so that the query box button "Yes" hides the bones and renders and the "no" button unhides the bones and renders? Looking at that piece of script i don't think it can.

tassel · 2011-06-16

Hi,

You can use "render()"

Or an example of rendering in you own Renderbuffer (VFB or what they call it these days)

on btn_render pressed do
(
RenderWindow = bitmap renderwidth renderheight --(W/H is collected from Render Settings. if you want a specified size just write "bitmap 200 200" or whatever)
displayRenderWindow
Render to:RenderWindow

escapeEnable = true
rendersavefile = false
)

Pre-render loading script issue....

Script_Butler · 2011-06-16

Cheers for that Tassel,

But it still doesn't solve the problem if the script is loaded in to the Pre-render list.

Is it possible to have a script that when run stops rendering until a button is pressed?

tassel · 2011-06-16

Do you you talking about "Pause" the render?

Script_Butler · 2011-06-16

I think that will work.

I appreciate if the script is run during normal max usage, the user can click on the render button and render the image.

But because I'd like my version to be usable when added in to the pre-render list, it would need an option to pause the render silently and then the user can turn off bones and click render!

Does that make sense?

br0t · 2011-06-16

just to note, there is a (code) ... (/code) context in this forum, (will work if you replace the round brackets with square brackets: [ ]) which will make your code much more readably through color coding :)

Code Context

Script_Butler · 2011-06-17

Thanks Br0t.

 

I will utilise this. 😎

Script_Butler · 2011-06-16

Hi Tassel,

It's effectively the script that your wrote with an extra button called Render.

Heres the script with some notes that i was thinking of.

--Destroy the dialog if it is already open
try(destroyDialog roll_SB_Tools)catch()

-- The first thing i want the script to do is when run is to stop rendering from happening if rendering has been clicked. If it hasn't then the script can run as normal and bones hidden/unhidden
-- at the moment if the script is added to pre-rendering it opens, but the rendering happens regardless so if the bones are on, the bones render. I would like this script to halt the rendering, you
--click hide bones and then when you click render the rendering begins again. I'm not sure if this would be suitable for network rendering though.

-- Create a rollout
rollout roll_SB_Tools "SB Tools V1.0"
(
-- UI STUFF
group "Hide / Unhide (Bones And Helpers)"
(
button btn_SBHide "..:: HIDE ::.." width:85 height:24 align:#left tooltip:"Hide bones and helpers" across:2
button btn_SBUnhide "..:: UNHIDE ::.." width:85 height:24 align:#right tooltip:"UN-Hide bones and helpers"
)
group "Render"
(
button btn_render "..::RENDER::.." width:85 height:24 align:#left tooltip:"Press to start rendering"
)

HyperLink hl_homepage "..:: MY SCRIPTS ::.." address:"http://www.scriptspot.com/users/script-butler/" color:(color 255 255 255) hovercolor:(color 111 111 111) visitedcolor:(color 255 255 255) height:22 align:#center
-------------------------------------------------------------------------------------------------------------------------------------------------------
-- GROUP "Hide / Unhide (bones and helpers)"
-------------------------------------------------------------------------------------------------------------------------------------------------------
on btn_SBHide pressed do
(
hideByCategory.bones = true
hideByCategory.helpers = true
)

on btn_SBUnhide pressed do
(
hideByCategory.bones = false
hideByCategory.helpers = false
)
-------------------------------------------------------------------------------------------------------------------------------------------------------
-- GROUP "Render"
-------------------------------------------------------------------------------------------------------------------------------------------------------
--on btn_render pressed do (I'M UNSURE ON SCRIPTING COMMANDS TO MAKE THE RENDER HAPPEN
--(
--START RENDERING COMMAND HERE
--)
-------------------------------------------------------------------------------------------------------------------------------------------------------

) -- End of script

--Create the dialog and stuff
createDialog roll_SB_Tools width:200 height:150

tassel · 2011-06-15

Hi,

Can you make an mock-up drawing of what you want, i don't thimk i fully understand it :o)

//Tassel