Hello.
I frequently and multiply bake simulations in the CUI.
Unlike baking in the GUI, I am having trouble seeing the performance of the process.
Is there any solution?
bpy.ops.ptcache.bake_all(bake=True)
I don’t know of any way to access this info so it could be printed out, but you could tap into a frame_change handler and calculate your own remaining time pretty easily. Just keep a running average of elapsed time between frame changes, and multiply by the remaining frames and strftime() to something human readable.
Thank you for your answer.
bpy.ops.ptcache.bake_all(bake=True)
I was under the mistaken impression that no operations could be performed during baking, so your hint was very helpful.
As for the CUI processing, I am calling it in a bat file as follows.
I also present the script.
Please let me know if there is a better improvement.
Windows batch file
chcp 65001
@echo off
set FILENAME=BlenderFileName
set FILEPATH=C:\tmp\
set BPY="C:\Users\username\OneDrive\blender\scripts\ptcachebake.py"
set BLENDER="C:\Program Files\Blender Foundation\Blender 3.4\blender.exe"
echo "----- Run Python Script -----"
%BLENDER% -b "%FILEPATH%%FILENAME%.blend" --python %BPY%
echo "----- End Python Script -----"
echo "---------- END Processing ----------
Python Script (ptcachebake.py)
import bpy, math
from datetime import datetime, timedelta
print("-------run")
print("-------physics bake free!")
bpy.ops.ptcache.free_bake_all()
######### Add
g_previous_time: datetime = ""
g_total_time: float = 0.0
def my_handler(scene):
current_time = datetime.now()
global g_previous_time
global g_total_time
previous_time = g_previous_time
g_previous_time = current_time
if previous_time and 0 != (scene.frame_current - scene.frame_start):
difference_time = current_time - previous_time
g_total_time += difference_time.total_seconds()
etstime = (((g_total_time / (scene.frame_current - scene.frame_start)) * scene.frame_end) - g_total_time)
print(
str("{:.1f}".format(difference_time.total_seconds())) + " sec " +
str("(avg {:.1f}".format((g_total_time / (scene.frame_current - scene.frame_start)))) + "s) / [" +
str(math.floor((g_total_time)/3600)) + "h " +
str(math.floor(((g_total_time)/60)%60)) + "m " +
str("{:.0f}".format(g_total_time%60)) + "s] " +
str("-----> {:.1f}".format(((scene.frame_current - scene.frame_start) / scene.frame_end)*100)) + "% " +
"-----> ETS:[" +
str(math.floor((etstime)/3600)) + "h " +
str(math.floor(((etstime)/60)%60)) + "m " +
str("{:.0f}".format(etstime%60)) + "s]"
)
elif g_total_time and 0 == ((scene.frame_current - scene.frame_start)):
difference_time = current_time - previous_time
g_total_time += difference_time.total_seconds()
etstime = (((g_total_time / scene.frame_end) * scene.frame_end) - g_total_time)
print(
str("{:.1f}".format(difference_time.total_seconds())) + " sec " +
str("(avg {:.1f}".format((g_total_time / (scene.frame_end)))) + "s) / [" +
str(math.floor((g_total_time)/3600)) + "h " +
str(math.floor(((g_total_time)/60)%60)) + "m " +
str("{:.0f}".format(g_total_time%60)) + "s] " +
str("-----> {:.1f}".format(((scene.frame_end) / scene.frame_end)*100)) + "% " +
"-----> ETS:[" +
str(math.floor((etstime)/3600)) + "h " +
str(math.floor(((etstime)/60)%60)) + "m " +
str("{:.0f}".format(etstime%60)) + "s]"
)
bpy.app.handlers.frame_change_pre.append(my_handler)
#########
print("--- physics bake start ---")
bpy.ops.ptcache.bake_all(bake=True)
print("---- physics bake end ----")
bpy.ops.wm.save_mainfile()
