PDA

View Full Version : post-render script after baking


Wheiraucher
03-05-2009, 08:32 AM
Hi.

well most is said in the title. Is there a way to run a script after a render to texture? The standard post-render-script doesn't work there.

I am using Max9.

thanks, David

ZeBoxx2
03-05-2009, 11:12 AM
use the standard callbacks, rather than the render scene dialog scripts;


callbacks.addScript #preRender "format \"#prerender\n\"; print (callbacks.notificationparam())" id:#test
callbacks.addScript #preRenderEval "format \"#preRenderEval\n\"" id:#test
callbacks.addScript #preRenderFrame "format \"#preRenderFrame\n\"" id:#test
callbacks.addScript #beginRenderingActualFrame "format \"#beginRenderingActualFrame \n\"" id:#test
callbacks.addScript #postRenderFrame"format \"#postRenderFrame\n\"" id:#test
callbacks.addScript #postRender"format \"#postRender\n\"" id:#test


You can detect whether it's RTT by checking element 1 of #preRender's notification params.. it will be #bakeSelected.

Wheiraucher
03-05-2009, 11:32 AM
wow. this looks really helpful. I still have to figure out exactly how callbacks work, and what your code does, but this is definitely pointing me in the right direction. thanks.

ZeBoxx2
03-05-2009, 07:23 PM
That snippet basically just sets up some callback handlers that print out the callback name. I've been using something similar with prettymuch all the callbacks whenever I think "I wonder if that triggers a callback...".

Figured I'd finally pack that up proper;
http://www.scriptspot.com/3ds-max/cblogger-callbacks-logger

As far as callbacks go... they're basically built-in functions that 3ds Max calls whenever a certain event occurs. E.g. when a render ends, it calls the #postRender callback. You could use that to then grab the last rendered image and save that to a file - a la the RenderHistory script(s)

Wheiraucher
03-06-2009, 10:20 AM
Hum..although i am registered at scriptspot I always get a access denied screen when clicking on your link.

Callbacks are truly a great way of adding features to 3dsmax (though i find it disturbing to script inside a string).

Unfortunately the render to texture dialog is not properly documented. I would like to have access to all the settings inside the dialog, especially the pathnames.

David

ZeBoxx2
03-06-2009, 11:13 AM
Hum..although i am registered at scriptspot I always get a access denied screen when clicking on your link.
Ah - I only *just* submitted them.. they may have to go through a review process that isn't quite explained on the pages... sorry about that. I suspect it'll become available shortly, but for now I'll attach it to this thread as well.

Callbacks are truly a great way of adding features to 3dsmax (though i find it disturbing to script inside a string).
So don't :)

Put all the code you need inside a function, and then simply call that function in the callback. E.g.

fn helloWorld = ( print "hello world" )
callbacks.addScript #preRender "helloWorld()" id:#test
-- callbacks.removescripts id:#test


Makes things much, much easier.


Unfortunately the render to texture dialog is not properly documented. I would like to have access to all the settings inside the dialog, especially the pathnames.
I think that the path names are actually stored in the objects;
showinterface $.inodebakeproperties

But if you do need access to that dialog specifically, you'd have to work with the UIAccessor bits.

ZeBoxx2
03-06-2009, 01:06 PM
might help if I didn't forget to attach.. let's try again :)

magicm
03-06-2009, 04:33 PM
Put all the code you need inside a function, and then simply call that function in the callback. E.g.

fn helloWorld = ( print "hello world" )
callbacks.addScript #preRender "helloWorld()" id:#test
-- callbacks.removescripts id:#test

One thing to note here though, is that if you decide to make your callbacks persistent (ie, saved with the scene), you'll need to make sure that the callback function (helloWorld in this case) is available when you close/start max and open the scene again.

Martijn

Wheiraucher
03-06-2009, 07:52 PM
Oh, wow, the callback logger is a useful tool. thanks. Amazing how many callbacks get sent after hitting render.
I think that the path names are actually stored in the objects;
ah ok. That's pretty comfortable.

Put all the code you need inside a function, and then simply call that function in the callback. E.g.

Hehe. that sure makes life easier :-)


But if you do need access to that dialog specifically, you'd have to work with the UIAccessor bits.

I searched the manual about this UIAccessor thing, and it looked pretty confusing. Any idea how to use it to get the render to texture path?

ZeBoxx2
03-07-2009, 02:08 AM
Oh, wow, the callback logger is a useful tool. thanks. Amazing how many callbacks get sent after hitting render.
Yep :)

I searched the manual about this UIAccessor thing, and it looked pretty confusing. Any idea how to use it to get the render to texture path?

Try with these functions:

-- <undefined|string>getRTTOutputPath()
-- gets the output path from the RTT dialog
-- Returns:
-- undefined - output path dialog element not found
-- string - the output path set in the RTT dialog
-- Notes:
-- The RTT dialog must be open
-- Example:
-- myPath = getRTTOutputPath()
fn getRTTOutputPath = (
local hwndchildren = windows.getChildrenHwnd (windows.getDesktopHWND())
local rttDialogFound = false
local outputPath = undefined
for child in hwndchildren do (
if (findString child[5] "Render To Texture" != undefined) do ( rttDialogFound = true )
if (rttDialogFound) then (
if (child[5] == "Path: ") then (
outputPath = UIAccessor.getWindowText (UIAccessor.getNextWindow child[1])
)
)
)
outputPath
)


-- <false|OK>setRTTOutputPath <string>path
-- sets the output path in the RTT dialog to the given path
-- Parameters:
-- path - the path to set. String.
-- Returns:
-- false - output path dialog element not found
-- OK - the output path was set in the RTT dialog
-- Notes:
-- The RTT dialog must be open
-- Example:
-- result = setRTTOutputPath myPath
fn setRTTOutputPath path = (
local hwndchildren = windows.getChildrenHwnd (windows.getDesktopHWND())
local rttDialogFound = false
local result = false
for child in hwndchildren do (
if (findString child[5] "Render To Texture" != undefined) do ( rttDialogFound = true )
if (rttDialogFound) then (
if (child[5] == "Path: ") then (
UIAccessor.setWindowText (UIAccessor.getNextWindow child[1]) path
result = OK
)
)
)
result
)

Wheiraucher
03-19-2009, 08:59 PM
Hi Zeboxx2. I am really sorry that it took me so long to reply to your last post. I hate these people who ask questions, get answers, and then never reply again. That is no decent behavior on a bulletin board. To my excuse, I have been on holiday with only little time for internet and and no computer with 3dsmax.

Your script does what it promises, which is great. thanks for taking the time to write those handy functions. I still have to figure how some of the commands work, but i understand the general flow. These scripts combined with a callback system and the $.INodeBakeProperties, are a perfect basis for my own script.

I had not expected that getting information from the rtt dialog would be so troublesome. But that's ok, because i learned a lot of cool new stuff.

thanks again, David

ZeBoxx2
03-19-2009, 09:32 PM
No prob - glad it worked out for you, and I hope you had a good holiday :)

CGTalk Moderation
03-19-2009, 09:32 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.