Batch rendering

Forums: Batch rendering
Foundry Modo (Developed by stenson, Integrated Plugin developed by Paul Kinnane)

Moderator: face_off

Batch rendering

Postby Deepwell » Mon Dec 11, 2023 8:55 am

Deepwell Mon Dec 11, 2023 8:55 am
I am trying to batch render with Octane.

My script does a "octane.command animate" - but that command immediately returns and so my script would go on to render the next scene.

Any idea how I can wait for octane to finish rendering the whole animation?

Cheers!
Johannes
Deepwell
Licensed Customer
Licensed Customer
 
Posts: 20
Joined: Fri Jan 15, 2021 4:07 pm

Re: Batch rendering

Postby face_off » Wed Dec 20, 2023 12:37 am

face_off Wed Dec 20, 2023 12:37 am
Hi Johannes - sorry for the late reply to this question.

There are potentially a couple of ways to do this. However I think the easiest way is to check if the 'octane.command animate' command is enabled. If it is - move to the next scene. If it is not enabled, then the current scene is still rendering. I am unsure how to check a command enabled state, but the Modo Foundry slack group would be able to help.

Another option is to check if the "octaneAnimationLayout" layout is open. Again, you would need to check the specifics on how to do this.

If you cannot get either of the above two options working - then I can add a command to the plugin to return the animation rendering status. There is already a similar command 'octane.getRenderStatus' to return if Octane is currently rendering.

Thanks

Paul
Win7/Win10/Mavericks/Mint 17 - GTX550Ti/GT640M
Octane Plugin Support : Poser, ArchiCAD, Revit, Inventor, AutoCAD, Rhino, Modo, Nuke
Pls read before submitting a support question
User avatar
face_off
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15483
Joined: Fri May 25, 2012 10:52 am
Location: Adelaide, Australia

Re: Batch rendering

Postby face_off » Wed Dec 20, 2023 1:14 am

face_off Wed Dec 20, 2023 1:14 am
Some more info on this.

You can determine if the current scene is rendering an animation with the following command:

Code: Select all
layout.createOrClose cookie:octaneAnimationLayoutCookie layout:octaneAnimationLayout ?


You would need to put this command in a loop, waiting on the animation to finish rendering, however the loop would block the Modo UI (and therefore stop the timeline from moving each frame), so you would need a PySide QProgressDialog window open to hook into it's UI thread, and call PySide2.QtWidgets.QApplication.processEvents() in the loop too. The general approach is shown in the post below. My guess is that you will need to be proficient in python to get this working.

https://render.otoy.com/forum/viewtopic.php?f=34&t=78755&start=20#p421893

Paul
Win7/Win10/Mavericks/Mint 17 - GTX550Ti/GT640M
Octane Plugin Support : Poser, ArchiCAD, Revit, Inventor, AutoCAD, Rhino, Modo, Nuke
Pls read before submitting a support question
User avatar
face_off
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15483
Joined: Fri May 25, 2012 10:52 am
Location: Adelaide, Australia

Re: Batch rendering

Postby Deepwell » Wed Dec 20, 2023 5:48 pm

Deepwell Wed Dec 20, 2023 5:48 pm
Hey Paul,
many thx for getting back to me about this and for the pointers.

The processEvent() is not enough in this case - the frame won't be advanced...

But with a little digging into Qt/PySide I managed to get something working (see attached).
Currently the scene list is simply hard coded into the script - enough for my use.

Now I'm off to the next issue: Motion Blur :mrgreen:
viewtopic.php?f=34&t=82819

Cheers!
J.

Code: Select all
#!/usr/bin/env python
###
# Octane Batch Rendering Script
# IMPORTANT:
# Make sure the "revert" and the "Octane Render Finished - reset the timeline..." dialogs are disabled!!!
# (answer the dialog once with do-not-ask-again...)
###

import modo
import lx

import time
import PySide2
import os
from PySide2.QtGui import *
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtWidgets import QFileDialog

scenes = [
    "E:\\ProjectX\FirstScene.lxo",
    "E:\\ProjectX\SecondScene.lxo",
]

def loadAndStartAnimation(sceneFilePath):
    global msgBox
    lx.eval(f"scene.open \"{sceneFilePath}\" normal")
    msgBox.setText(f"Rendering: {os.path.basename(sceneFilePath)}")
    lx.eval("octane.command animate")

def cancelBatch():
    global continueBatch
    continueBatch = False
    print("Canceling batch\n")
    lx.eval("octane.command cancelAnimation")

def checkAndAdvance():
    global msgBox, scenes, continueBatch
    print("Checking\n")
    rendering = lx.eval("layout.createOrClose cookie:octaneAnimationLayoutCookie layout:octaneAnimationLayout ?")
    if rendering == 0:
        print("Advancing to next scene\n")
        # We do not want to remove the "unsaved" warning from the "close" dialog
        # So we remove the warning from the "revert" dialog and use that before doing the close
        lx.eval("scene.revert")
        lx.eval("scene.close")
        if scenes and continueBatch:
            nextScene = scenes.pop(0)
            loadAndStartAnimation(nextScene)
            checkAndAdvance()
        else:
            print("Done.\n")
            msgBox.hide()
    else:
        QTimer.singleShot(1000, checkAndAdvance)

msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Information)
msgBox.setText("...")
msgBox.setWindowTitle("Octane Batch Rendering")
msgBox.setStandardButtons(QMessageBox.Cancel)
msgBox.buttonClicked.connect(cancelBatch)
msgBox.show()

continueBatch = True
currentScene = scenes.pop(0)
loadAndStartAnimation(currentScene)
QTimer.singleShot(1000, checkAndAdvance)

Deepwell
Licensed Customer
Licensed Customer
 
Posts: 20
Joined: Fri Jan 15, 2021 4:07 pm

Re: Batch rendering

Postby Deepwell » Wed Dec 20, 2023 6:56 pm

Deepwell Wed Dec 20, 2023 6:56 pm
I just found an issue with the script code - the direct recursive call of checkAndAdvance is not ideal...(works, but can be problematic). Also I found out that fortunately on Windows it is not necessary to use the loathed backslashes in the path...:)

Corrected code:

Code: Select all
#!/usr/bin/env python
###
# Octane Batch Rendering Script
# IMPORTANT:
# Make sure the "revert" and the "Octane Render Finished - reset the timeline..." dialogs are disabled!!!
# (answer the dialog once with do-not-ask-again...)
###

import modo
import lx

import time
import PySide2
import os
from PySide2.QtGui import *
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtWidgets import QFileDialog

scenes = [
    "E:/ProjectX/FirstScene.lxo",
    "E:/ProjectX/SecondScene.lxo",
]

def loadAndStartAnimation(sceneFilePath):
    global msgBox
    lx.eval(f"scene.open \"{sceneFilePath}\" normal")
    msgBox.setText(f"Rendering: {os.path.basename(sceneFilePath)}")
    lx.eval("octane.command animate")

def cancelBatch():
    global continueBatch
    continueBatch = False
    print("Canceling batch\n")
    lx.eval("octane.command cancelAnimation")

def checkAndAdvance():
    global msgBox, scenes, continueBatch
    print("Checking\n")
    rendering = lx.eval("layout.createOrClose cookie:octaneAnimationLayoutCookie layout:octaneAnimationLayout ?")
    if rendering == 0:
        print("Advancing to next scene\n")
        # We do not want to remove the "unsaved" warning from the "close" dialog
        # So we remove the warning from the "revert" dialog and use that before doing the close
        lx.eval("scene.revert")
        lx.eval("scene.close")
        if scenes and continueBatch:
            nextScene = scenes.pop(0)
            loadAndStartAnimation(nextScene)
            QTimer.singleShot(1000, checkAndAdvance)
        else:
            print("Done.\n")
            msgBox.hide()
    else:
        QTimer.singleShot(1000, checkAndAdvance)

msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Information)
msgBox.setText("...")
msgBox.setWindowTitle("Octane Batch Rendering")
msgBox.setStandardButtons(QMessageBox.Cancel)
msgBox.buttonClicked.connect(cancelBatch)
msgBox.show()

continueBatch = True
currentScene = scenes.pop(0)
loadAndStartAnimation(currentScene)
QTimer.singleShot(1000, checkAndAdvance)
Deepwell
Licensed Customer
Licensed Customer
 
Posts: 20
Joined: Fri Jan 15, 2021 4:07 pm

Return to Foundry Modo


Who is online

Users browsing this forum: No registered users and 41 guests

Sat Apr 27, 2024 5:33 pm [ UTC ]