# Shutdown after render script (for windows) # by Monaime import bpy , os , math , time from bpy.props import * # creating the UI class ShutdownUI(bpy.types.Panel): bl_label = "Shutdown after render" bl_idname = "Shutdown_UI" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' def draw(self, context): layout = self.layout row = layout.row() row.prop(context.scene, "Shutdown_Pass", text="Password") row = layout.row() row.prop(context.scene, "Shutdown_Animation", text="Render animation") row = layout.row() row.prop(context.scene, "Shutdown_Path", text="Path") row = layout.row() row.enabled = not bpy.context.scene.Shutdown_Animation row.prop(context.scene, "Shutdown_Name", text="File name") row = layout.row() row.prop(context.scene, "Shutdown_Wait", text="Wait") row = layout.row() row.prop(context.scene, "Shutdown_Info", text="Print info") row = layout.row() row.operator("render.shutdown",text="Render then shutdown") # the main programme def main(self, context): # getting some variables from the panel scn = bpy.context.scene anim = scn.Shutdown_Animation # Render animation? path = scn.Shutdown_Path # where the file will be saved image_name = scn.Shutdown_Name # name of the file image_extension = scn.render.file_extension # the extension of the file from the render section waittime = str(scn.Shutdown_Wait) # time to wait Pass = scn.Shutdown_Pass # Password # if the path is not accessible then report a warning message if os.access(path,os.F_OK) == False: scn.Shutdown_Path = '' self.report({'WARNING'}, "Wrong path") # else continue else: starttime = int(time.time()) # get the current time started = time.strftime("%a, %d %b %Y, %H:%M:%S ", time.gmtime()) # formate the current time # if the render is finished if bpy.ops.render.render(animation = anim) == {'FINISHED'} : # if its not an animation then save the image if not anim : bpy.data.images['Render Result'].save_render(path + image_name + image_extension, scene = None) # whene the render is finished get the time endtime = int(time.time()) finished = time.strftime("%a, %d %b %Y, %H:%M:%S ", time.gmtime()) # creating the info.txt file if scn.Shutdown_Info : f2 = open(path + 'info.txt', 'w') rendertime = endtime - starttime H = str(int(rendertime // 3600)) if len(H) == 1: H = '0'+H M = str(int((math.fmod(rendertime , 3600))//60)) if len(M) == 1: M = '0'+M S = str(int((math.fmod(rendertime , 60)) )) if len(S) == 1: S = '0'+S f2.write('This file was generated by python script containing informations about the last render.' + '\n' + '\n' + '-----------------------------------' + '\n' + '\n' + '- Started : ' + started + '\n' + '\n' + '- Finished : ' + finished + '\n' + '\n' + '- Render time : ' + H + ':' + M + ':' + S) f2.close() # shutdown the computer os.system('echo '+Pass+' | sudo -S shutdown -h +' + waittime) class Shutdown(bpy.types.Operator): bl_idname = "render.shutdown" bl_label = "Execute" bl_description = "Render the scene then shutdown the computer." def execute(self, context): main(self, context) return {'FINISHED'} def abore(self, context) : os.system('shutdown -a') class Abore(bpy.types.Operator): bl_idname = "render.abore" bl_label = "Abore" bl_description = "Abort the shutdown." def execute(self, context): abore(self,context) return {'FINISHED'} def set_path(self,context): bpy.context.scene.render.filepath = bpy.context.scene.Shutdown_Path return None def register(): bpy.utils.register_class(Abore) def unregister(): bpy.utils.unregister_class(Abore) def register(): bpy.utils.register_class(Shutdown) def unregister(): bpy.utils.unregister_class(Shutdown) def register(): bpy.utils.register_class(ShutdownUI) def unregister(): bpy.utils.unregister_class(ShutdownUI) def register(): bpy.utils.register_module(__name__) bpy.types.Scene.Shutdown_Animation = bpy.props.BoolProperty(name="Animation", description="Render animation or not.", default=False) bpy.types.Scene.Shutdown_Path = bpy.props.StringProperty(name="Path", description="Where the file will be saved.",default="", maxlen=100, subtype = 'DIR_PATH', update = set_path) bpy.types.Scene.Shutdown_Name = bpy.props.StringProperty(name="Name", description="Name of the rendred image.",default="Untitled", maxlen=50) bpy.types.Scene.Shutdown_Pass = bpy.props.StringProperty(name="Pass", description="Enter the login password.",default="", maxlen=100) bpy.types.Scene.Shutdown_Wait = bpy.props.IntProperty(name="Wait", description="Time to wait in Minutes between the end of th render and the shutdown.", default=1,min=1,max=7200) bpy.types.Scene.Shutdown_Info = bpy.props.BoolProperty(name="Info", description="Save a txt file containing informations about the render time in the same location as the rendred image(s).", default=True) def unregister(): bpy.utils.unregister_module(__name__) del bpy.types.Scene.Shutdown_Animation del bpy.types.Scene.Shutdown_Path del bpy.types.Scene.Shutdown_Name del bpy.types.Scene.Shutdown_Pass del bpy.types.Scene.Shutdown_Wait del bpy.types.Scene.Shutdown_Info if __name__ == "__main__": register()