63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
|
info = {
|
||
|
'icon' : 'RENDER_STILL',
|
||
|
'description' : 'render still image timed',
|
||
|
}
|
||
|
|
||
|
import bpy
|
||
|
import os
|
||
|
from os import listdir
|
||
|
from os.path import join, dirname, basename, exists, isfile, isdir, splitext
|
||
|
import re, fnmatch, glob
|
||
|
from mathutils import Vector, Matrix
|
||
|
from math import radians, degrees
|
||
|
from time import time
|
||
|
import datetime
|
||
|
|
||
|
C = bpy.context
|
||
|
D = bpy.data
|
||
|
scn = scene = C.scene
|
||
|
rd = scn.render
|
||
|
|
||
|
|
||
|
|
||
|
def pad_with_current_frame(match):
|
||
|
return str(C.scene.frame_current).zfill(len(match.group(0)))
|
||
|
|
||
|
def add_frame_padding(name):
|
||
|
'''
|
||
|
return string padded with current blender frame
|
||
|
if # found, use this padding to write theframe
|
||
|
'''
|
||
|
import re
|
||
|
if not '#' in name: return name + str(C.scene.frame_current).zfill(4)
|
||
|
# return re.sub(r'\#{1,10}', pad_with_current_frame, name)# all '#...' in string
|
||
|
return re.sub(r'\#{1,10}(?!.*\#)', pad_with_current_frame, name)# only last '#...'
|
||
|
|
||
|
|
||
|
def render(anim=False, GL=False):
|
||
|
if GL:#openGl render
|
||
|
bpy.ops.render.opengl(animation=anim, write_still=True, view_context=True)#view_context False > look throughcam
|
||
|
else:
|
||
|
bpy.ops.render.render(animation=anim, write_still=True)
|
||
|
|
||
|
start = time()
|
||
|
|
||
|
orgfp = C.scene.render.filepath
|
||
|
C.scene.render.filepath = add_frame_padding(C.scene.render.filepath)
|
||
|
|
||
|
try:
|
||
|
render(anim=False)
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
finally:
|
||
|
C.scene.render.filepath = orgfp
|
||
|
|
||
|
secs = time() - start
|
||
|
timesec_str = f'elapsed {secs} seconds'
|
||
|
time_str = str(datetime.timedelta(seconds=secs))
|
||
|
|
||
|
print(timesec_str)
|
||
|
print(time_str)
|
||
|
C.window_manager.clipboard = time_str
|
||
|
|