save layered .EXR (render passes) using command line

Forums: save layered .EXR (render passes) using command line
Forum for OctaneRender Lua scripting examples, discussion and support.

save layered .EXR (render passes) using command line

Postby tomsawyer » Thu Jun 22, 2017 4:05 pm

tomsawyer Thu Jun 22, 2017 4:05 pm
Hi,
I need some help using the --script switch from within the command line (octane standalone).

I am using the command line to batch render a set of different cameras (no animation, just a bunch of different cameras for many static scenes).
This workflow worked for single passes. But now I need to output different render passes for each camera and I'd want to save each image in a layered .EXR.

The command line won't let me output layered .EXR - I have tried setting the scene with render passes, the .exr's rendered with command line only contain the "main" image (set in the kernel).

On the other hand, this lua function is doing exactly what I need:

Code: Select all
octane.render.saveRenderPassesMultiExr("D:\\TEST\\layered.exr", renderPassObjects)     


I saved a lua script containing this function and tried to call this from within the .bat. using the --script switch,
This is a line from my .bat (I have hundreds of those lines):

Code: Select all
"C:\Program Files\OTOY\OctaneRender 3.05.3\octane-cli.exe" -e --cam-pos-x 0.0 --cam-target-x 0.0 --cam-pos-y 1.73424 --cam-target-y 1.73424 --cam-pos-z 0.819558 --cam-target-z -0.180442 --cam-fov 360 --cam-scale 2 --no-gui -q -t "Render target" --samples 200 --film-width 1024 --film-height 512 --output-png color0.png  --script "D:\TEST\saveRenderPasses.lua" color.orbx


But I get this error: "An unhandled win32 exception occured in octane.exe [16996]"

This is probably because the script tries to save images before any image has been rendered...
Could anyone help me to get this working / point me in the right direction?

PS: reading through the forums I understand that writing a lua script for batch-rendering all the cameras would be far more advantageous then using the command line .... my problem is that I already have a lot of .bat files with different camera positions so the immediate solution for me is to use those .bat files to batch-render layered .EXR's (containing all render passes)

TS
“It's not what you don't know that kills you, it's what you know for sure that ain't true.” - Mark Twain
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby tomsawyer » Wed Jul 05, 2017 2:46 pm

tomsawyer Wed Jul 05, 2017 2:46 pm
OK, talking to myself here. It's still helpful:

I managed to create a lua script that will save a multi-pass EXR when called from the command line .bat:

Code: Select all
octane.gui.dispatchGuiEvents(30000)

local function createRenderPassExportObjs(renderPassesNode)
    local objects = {}
    for _, renderPassId in ipairs(octane.render.getAllRenderPassIds()) do
        local info = octane.render.getRenderPassInfo(renderPassId)
        if info.pinId ~= octane.P_UNKNOWN then
            -- if the render pass is enabled -> add it to the export objects
            if renderPassesNode:getPinValue(info.pinId) then
                local exportObj =
                {
                    ["exportName"]   = info.name,
                    ["origName"]     = info.name,
                    ["renderPassId"] = info.renderPassId,
                }
                table.insert(objects, exportObj)
            end
        else
            local exportObj =
            {
                ["exportName"]   = info.name,
                ["origName"]     = info.name,
                ["renderPassId"] = info.renderPassId,
            }
            table.insert(objects, exportObj)
        end
    end
    return objects
end

local RT = octane.render.getRenderTargetNode()
local exportObjects = createRenderPassExportObjs(RT:getInputNode(octane.P_RENDER_PASSES))

local filePath = "D:\\WORK_LOCAL\\OCTANE_scenes\\BatchExportEXR\\"
local fileName = "Image_"
local sysTime = tostring(os.time())
local fullFilePath = (filePath..fileName..sysTime..".exr")

success = octane.render.saveRenderPassesMultiExr(fullFilePath, exportObjects)


I have used the octane.gui.dispatchGuiEvents(30000) to delay the execution, I am surprised it works as it supposedly works for GUI elements only... anyway, I will use the octane.timer next time. I had to use this as I was not successful in triggering the saveRenderPassesMultiExr function when samples are reached. I would appreciate any help.
Does anyone know how to close the Octane application from LUA script? I have searched the LUA API documentation and the forum but couldn't find anything. Does octane LUA have such a function?

Thanks!
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby tomsawyer » Wed Jul 05, 2017 4:24 pm

tomsawyer Wed Jul 05, 2017 4:24 pm
Does anyone know how to close/exit Octane instance (standalone) using LUA?
It is the last bit I need for my script.

The code for exporting multi-pass exr using octane batch files - if anybody needs this:
Now the images are exported after the rendering is finished (max samples are reached)

Code: Select all
local function createRenderPassExportObjs(renderPassesNode)
    local objects = {}
    for _, renderPassId in ipairs(octane.render.getAllRenderPassIds()) do
        local info = octane.render.getRenderPassInfo(renderPassId)
        if info.pinId ~= octane.P_UNKNOWN then
            -- if the render pass is enabled -> add it to the export objects
            if renderPassesNode:getPinValue(info.pinId) then
                local exportObj =
                {
                    ["exportName"]   = info.name,
                    ["origName"]     = info.name,
                    ["renderPassId"] = info.renderPassId,
                }
                table.insert(objects, exportObj)
            end
        else
            local exportObj =
            {
                ["exportName"]   = info.name,
                ["origName"]     = info.name,
                ["renderPassId"] = info.renderPassId,
            }
            table.insert(objects, exportObj)
        end
    end
    return objects
end

local RT = octane.render.getRenderTargetNode()
local exportObjects = createRenderPassExportObjs(RT:getInputNode(octane.P_RENDER_PASSES))

local filePath = "D:\\WORK_LOCAL\\OCTANE_scenes\\BatchExportEXR\\"
local fileName = "Image_"
local sysTime = tostring(os.time())
local fullFilePath = (filePath..fileName..sysTime..".exr")

octane.gui.dispatchGuiEvents(15000)

local function isDone()
    renderIsDone = false
    stats = octane.render.getRenderResultStatistics()
    if (stats.renderState == 4) then renderIsDone = true end
    return renderIsDone
end

while (isDone() ~= true) do octane.gui.dispatchGuiEvents(3000) end

success = octane.render.saveRenderPassesMultiExr(fullFilePath, exportObjects)
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby tomsawyer » Thu Jul 06, 2017 9:25 am

tomsawyer Thu Jul 06, 2017 9:25 am
Found it!: --stop-after-script in .bat file will exit the octane instance once the lua script has been executed - exactly what I needed!
I can finally use the above LUA script to save sequences of multi-pass EXR from my batch files... woohoo!!!

However, it would be nice to be able to pass an argument (i.e. filename) using the --script-arg line in .bat.

Does anyone out there know how to use --script-arg in batch files ???
I've put some string after --script-arg but I have no idea how to retrieve the arguments in LUA.... I red somewhere that SCRIPT_ARGUMENT is the table containing all the arguments passed by the batch file. However trying to use SCRIPT_ARGUMENT breaks my script. I also tried SCRIPT_ARGUMENT[1]
Does anyone know the magic variable/table name for batch arguments, please?
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby tomsawyer » Thu Jul 06, 2017 11:42 am

tomsawyer Thu Jul 06, 2017 11:42 am
Found it here:
viewtopic.php?f=73&t=39600

arg - table containing all arguments specified in the .bat file
arg[1] - first argument specified in the batch file ( using --script-arg or -a)
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby Notiusweb » Fri Jul 07, 2017 1:39 pm

Notiusweb Fri Jul 07, 2017 1:39 pm
Re: save layered .EXR (render passes) using command line
Unread postby tomsawyer » Wed Jul 05, 2017 11:24 am
Does anyone know how to close/exit Octane instance (standalone) using LUA?
It is the last bit I need for my script.


I actually was able to crash Octane with a script, would you like to have that? At the end of your script there could be a forced crash, maybe with a timed delay it would work!
Win 10 Pro 64, Xeon E5-2687W v2 (8x 3.40GHz), G.Skill 64 GB DDR3-2400, ASRock X79 Extreme 11
Mobo: 1 Titan Xp, 1 Titan X Pascal
External: 6 Titan X Pascal - 1600W EVGA T2
Plugs: 3DSMax, C4D, Daz, Houdini, Lightwave, Sketchup
User avatar
Notiusweb
Licensed Customer
Licensed Customer
 
Posts: 1181
Joined: Mon Nov 10, 2014 4:51 am

Re: save layered .EXR (render passes) using command line

Postby tomsawyer » Mon Jul 10, 2017 9:42 am

tomsawyer Mon Jul 10, 2017 9:42 am
Notiusweb wrote:I actually was able to crash Octane with a script, would you like to have that? At the end of your script there could be a forced crash, maybe with a timed delay it would work!
Actually...
No.

But thanks anyway! :lol:

Octane batch: " -e, --exit Close the application when rendering is done"

If anyone else struggles with how to pass an argument from batch to LUA: use -a "someString" in .bat; this will be passed to LUA as arg[1];
You can use multiple arguments in .bat.

I'm finally able to export multi-pass EXR sequences using octane batch files.
thanks for input notiousweb ;)
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby tomsawyer » Wed Jul 12, 2017 4:47 pm

tomsawyer Wed Jul 12, 2017 4:47 pm
If anyone else needs to render multi-pass EXR using command line:
create a "batchMultiExr.lua" file (where your .bat file is located) with this code:

Code: Select all
local function createRenderPassExportObjs(renderPassesNode)
    local objects = {}
    for _, renderPassId in ipairs(octane.render.getAllRenderPassIds()) do
        local info = octane.render.getRenderPassInfo(renderPassId)
        if info.pinId ~= octane.P_UNKNOWN then
            if renderPassesNode:getPinValue(info.pinId) then
                local exportObj =
                {
                    ["exportName"]   = info.name,
                    ["origName"]     = info.name,
                    ["renderPassId"] = info.renderPassId,
                }
                table.insert(objects, exportObj)
            end
        else
            local exportObj =
            {
                ["exportName"]   = info.name,
                ["origName"]     = info.name,
                ["renderPassId"] = info.renderPassId,
            }
            table.insert(objects, exportObj)
        end
    end
    return objects
end
local function isDone()
    renderIsDone = false
    stats = octane.render.getRenderResultStatistics()
    if (stats.renderState == 4) then renderIsDone = true end
    return renderIsDone
end
local RT = octane.render.getRenderTargetNode()
local exportObjects = createRenderPassExportObjs(RT:getInputNode(octane.P_RENDER_PASSES))
local fileName = arg[1]
local fullFilePath = (fileName..".exr")
while (isDone() ~= true) do octane.gui.dispatchGuiEvents(3000) end
success = octane.render.saveRenderPassesMultiExr(fullFilePath, exportObjects)


And use the following switches in .bat:
--script "%~dp0\batchMultiExr.lua" (this will call the above script once octane is launched)
-a "color0" (incremented with each line - will be used as the name of the .exr)
--stop-after-script (have to use this in order to close the octane and let the .bat execute the next line... if not used, it will hang after the first image; do not use -e as this will exit octane once the frame is rendered and will not let the script export the .exr)

... along with any other optional settings you may need. For example:
"C:\Program Files\OTOY\OctaneRender 3.05.3\octane-cli.exe" -q --cam-pos-x -0.23333 --cam-target-x -0.23333 --cam-pos-y -0.23333 --cam-target-y -0.23333 --cam-pos-z 0.23333 --cam-target-z -0.76667 --cam-fov 360 --cam-scale 2 -t "Render target" --film-width 2048 --film-height 1024 --script "%~dp0\batchMultiExr.lua" -a "color0" --stop-after-script --samples 50 passes.orbx

"C:\Program Files\OTOY\OctaneRender 3.05.3\octane-cli.exe" -q --cam-pos-x -0.23333 --cam-target-x -0.23333 --cam-pos-y 0.00000 --cam-target-y 0.00000 --cam-pos-z 0.23333 --cam-target-z -0.76667 --cam-fov 360 --cam-scale 2 -t "Render target" --samples 50 --film-width 2048 --film-height 1024 --script "%~dp0\batchMultiExr.lua" -a "color1" --stop-after-script passes.orbx

...and so on.


I think command line is still valuable - if you want to pass different arguments (like camera positions) from other packages and not worry about setting up the scene in octane standalone.

Otherwise, LUA seems a great addition for standalone. worth learning!
tomsawyer
 
Posts: 11
Joined: Thu Jun 22, 2017 2:13 pm

Re: save layered .EXR (render passes) using command line

Postby Notiusweb » Sat Jul 15, 2017 5:24 am

Notiusweb Sat Jul 15, 2017 5:24 am
... along with any other optional settings you may need.


Oooooh!
Thanks!
:D
Win 10 Pro 64, Xeon E5-2687W v2 (8x 3.40GHz), G.Skill 64 GB DDR3-2400, ASRock X79 Extreme 11
Mobo: 1 Titan Xp, 1 Titan X Pascal
External: 6 Titan X Pascal - 1600W EVGA T2
Plugs: 3DSMax, C4D, Daz, Houdini, Lightwave, Sketchup
User avatar
Notiusweb
Licensed Customer
Licensed Customer
 
Posts: 1181
Joined: Mon Nov 10, 2014 4:51 am

Re: save layered .EXR (render passes) using command line

Postby doca » Wed Aug 16, 2017 3:27 pm

doca Wed Aug 16, 2017 3:27 pm
Hi Tom,

Trying to run your script with Octane 3.06.4 but I get error:"Render target is not a render target node"

Here's my try:
Z:\!install\3d\OctaneRender\octane-cli.exe -q -t "Render target" --script "%~dp0\batchMultiExr.lua" -a P:\17072_Mx_vs_Atv\render\testDeadline\testRender_1" --stop-after-script P:\17072_Mx_vs_Atv\tasks\ASSETS\rider\SHADING\tempDeadline.ocs

Guess I'm doing something wrong here...

Thanks.
doca
Licensed Customer
Licensed Customer
 
Posts: 81
Joined: Sat Mar 13, 2010 12:12 pm
Next

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 1 guest

Thu Dec 12, 2019 12:47 am [ UTC ]