Skip to content

Commit

Permalink
Fixed unnamed render bug
Browse files Browse the repository at this point in the history
You no longer have to ensure that you have named your blend file, or your render.
The blend file will automatically be called 'untitled.blend' if no other name is given.
The render will automatically be named after the time the file was opened, called - HourMinuteSecond.PNG - or whatever the file extension is

I was able to pass this info in through handlers, so you should be able to render and email and ALMOST unchanged scene.
Unfortunately, the catch for this is that you must make some kind of adjustment to you scene manually.
If you try to render on a completely untouched scene, it will still fail, however, if you make even a tiny change to the scene, it will work.
If you move, scale, rotate an object, change a material value, the scene's start or end frame, even if you immediately change it back, that will trigger the depsgraph to update and allow the addon to rename and save the render. Otherwise it gives the same "File not found" error.

I thought I'd be able to trigger an update by running one of those commands in a post_load handler, but it appears to only work when a user does it manually.
  • Loading branch information
SpectralVectors authored Apr 10, 2022
1 parent 5c57da1 commit a55f424
Showing 1 changed file with 68 additions and 49 deletions.
117 changes: 68 additions & 49 deletions RenderReminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
'name': 'RenderReminder',
'category': 'Render',
'author': 'Spectral Vectors',
'version': (0, 2, 1),
'version': (0, 2, 2),
'blender': (3, 00, 0),
'location': 'Addon Preferences',
'description': 'Send an email and play a sound upon render completion.'
}

import aud, bpy, datetime, pathlib, smtplib, ssl
import aud, bpy, datetime, os, pathlib, smtplib, ssl

from bpy.props import (StringProperty,
BoolProperty,
Expand All @@ -28,42 +28,6 @@
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

device = aud.Device()

def coinSound():
sound = aud.Sound('')
handle = device.play(
sound
.triangle(1000)
.highpass(20)
.lowpass(2000)
.ADSR(0,0.5,1,0)
.fadeout(0.1,0.1)
.limit(0,1)
)

handle = device.play(
sound
.triangle(1500)
.highpass(20)
.lowpass(2000)
.ADSR(0,0.5,1,0)
.fadeout(0.2,0.2)
.delay(0.1)
.limit(0,1)
)
def ding():
sound = aud.Sound('')
handle = device.play(
sound
.triangle(3000)
.highpass(20)
.lowpass(1000)
.ADSR(0,0.5,1,0)
.fadeout(0,1)
.limit(0,1)
)


class RenderReminderAddonPreferences(AddonPreferences):
bl_idname = __name__
Expand Down Expand Up @@ -180,14 +144,20 @@ def execute(self, context):
receiver_email = addon_prefs.receiver_email
password = addon_prefs.password

shortfilename = bpy.path.display_name_from_filepath(bpy.context.blend_data.filepath)
longfilename = bpy.path.basename(bpy.context.blend_data.filepath)
renderfile = bpy.context.scene.render.filepath
render = bpy.path.basename(renderfile)
file_extension = pathlib.Path(bpy.context.scene.render.filepath).suffix
filename = bpy.context.blend_data.filepath

if filename == '':
filename = 'untitled.blend'

shortfilename = bpy.path.display_name_from_filepath(filename)
longfilename = bpy.path.basename(filename)

now = datetime.datetime.now()
date_time = now.strftime("%H:%M:%S, %m/%d/%Y")

renderfile = bpy.context.scene.render.filepath
render = bpy.path.basename(renderfile)
file_extension = pathlib.Path(bpy.context.scene.render.filepath).suffix

msg = MIMEMultipart()
msg['From'] = sender_email
Expand All @@ -200,7 +170,6 @@ def execute(self, context):
msg.attach(msg_content)

if addon_prefs.includerender:

with open(renderfile, 'rb') as f:
mime = MIMEBase('image', file_extension, filename=render)
mime.add_header('Content-Disposition', 'attachment', filename=render)
Expand All @@ -211,17 +180,49 @@ def execute(self, context):
msg.attach(mime)
f.close()


context = ssl.create_default_context()

if addon_prefs.sendemail:

context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email.split(','), msg.as_string())


if addon_prefs.playsound:
device = aud.Device()

def coinSound():
sound = aud.Sound('')
handle = device.play(
sound
.triangle(1000)
.highpass(20)
.lowpass(2000)
.ADSR(0,0.5,1,0)
.fadeout(0.1,0.1)
.limit(0,1)
)

handle = device.play(
sound
.triangle(1500)
.highpass(20)
.lowpass(2000)
.ADSR(0,0.5,1,0)
.fadeout(0.2,0.2)
.delay(0.1)
.limit(0,1)
)
def ding():
sound = aud.Sound('')
handle = device.play(
sound
.triangle(3000)
.highpass(20)
.lowpass(1000)
.ADSR(0,0.5,1,0)
.fadeout(0,1)
.limit(0,1)
)

if addon_prefs.soundselect == 'ding':
ding()
if addon_prefs.soundselect == 'coin':
Expand All @@ -233,6 +234,20 @@ def execute(self, context):

return {'FINISHED'}

@persistent
def autoNameRender(dummy):
property = bpy.context.window_manager.operator_properties_last("render.render")
property.write_still = True

bpy.context.scene.render.use_render_cache = True

if bpy.context.scene.render.filepath == '/tmp\\':
now = datetime.datetime.now()
rendernamer = now.strftime("%H%M%S")
path = '~\Documents\\'
filepath = os.path.expanduser(path) + rendernamer + '.' + bpy.context.scene.render.image_settings.file_format
bpy.context.scene.render.filepath = filepath

@persistent
def sendEmail(dummy):
bpy.ops.renderreminder.send_email()
Expand All @@ -251,13 +266,17 @@ def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)

bpy.app.handlers.load_post.append(autoNameRender)
bpy.app.handlers.render_complete.append(sendEmail)
bpy.app.handlers.depsgraph_update_pre.append(writeRender)

def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)

bpy.app.handlers.load_post.remove(autoNameRender)
bpy.app.handlers.render_complete.remove(sendEmail)
bpy.app.handlers.depsgraph_update_pre.remove(writeRender)

Expand Down

0 comments on commit a55f424

Please sign in to comment.